Testing the Application
In the interest of simplicity I have assumed that data sent over the TCP stream are sent and received in the same block. However, this is not always true. Data sent over the TCP stream are not guaranteed to arrive at once; you may receive a portion of the message in the current read cycle and receive the rest in the next read cycle, or several messages may be read at the same time.
In this case, you need to modify your application so that you are able to differentiate the different messages sent by the user.
To test the application, first run the server by pressing F5 in Visual Studio 2005. You want to launch multiple copies of the client to test the multi-user capabilities of the server. To do this, compile the code files provided with this article into an .exe file. Run multiple copies of Winclient.exe and sign in and chat at the same time.
In this article, I have shown how you can define your own protocols to build a robust chat application. It's a fun application that will also help you learn to do some sophisticated tasks using network programming in .NET.