One of the reasons I got motivated to start writing this blog was a recent spate of questions in the C# newsgroup about networking using .NET. These come up now and then, and I don’t know of any reasonably comprehensive introductory resource specific to networking APIs in .NET.
There are some good resources in the context of the unmanaged Winsock API in Windows, and those would in fact be useful even to someone trying to understand the .NET API. But .NET is subtly different in some ways, and provides easy access to some of the more complicated parts of Winsock in other ways. I think there are books on the topic, but at least the basics of networking in API isn’t really all that complicated. So why not attempt to write up a .NET-specific series of posts that provide the introduction that should have been in the MSDN documentation? (Ironically, MSDN does in fact have over a dozen .NET networking samples, but all are to demonstrate specific technologies or protocols, rather than being suitable as an introduction).
So, what’s that got to do with “a Forms control for receiving text output”? Well, networking applications often send data back and forth, and it’s often nice to have a way to watch the data as it goes by. For this purpose, one could use a ListBox or TextBox and just add new lines of text as they show up. But that brings up another question that I’ve seen at least a couple of times, which is how to get those controls to work more like a typical text output console?
Those controls mostly would work fine, just to get the job done. But what if you want a console with a limited, but large number of lines? These other controls can be a bit unwieldy as they’re not really designed for that purpose. The ListBox only supports selection of entire lines at once, while the TextBox isn’t as good at removing text on a line-by-line basis. What if we could have the best of both worlds?
At the same time, it’s probably helpful to me to not just dive in to the networking stuff, but rather to get a feel for this whole “blog about code” thing with something less ambitious. So, while existing Forms controls would in fact be perfectly sufficient for our needs, a nice simple console-like control gives me an opportunity to “warm up” while at the same time providing a code sample that would be useful not only in any networking samples, but also for some of the other .NET questions I’ve seen having to do with writing custom controls.
For next time: the SimpleConsole class.