TCP Socket War (C# and TcpListener)
I have just spent the better part of two days fighting a socket bug that turned out to be a simple fix. Isn't it funny how the time consuming ones always turn out to be something simple? I have been using .Net's TcpListener to create a server/client applications. The advantage of using the TcpListener is that it does all of the standard socket setup for you. You also still have access to the socket and the network stream that is used in case you still need the extra power that comes with manipulating them yourself. The way I set this thing up is by having both the client and server loop forever to listen for incoming data. This is done using BeginRead(...) on the network stream. myTcpClient.GetStream().BeginRead(data, 0, size, new AsyncCallback(dataReceived), state); This will have the app listen on another thread so that I can do my other business. When data is received, the callback method that was passed in will be called. What is cool about this is that you can still send o...