Professional .NET Network Programming
[I'm new, this is my first post, in case you dont recognize my username]
hopefully someone can answer this for me, I've tried investigating this a little bit but cant find anything concrete. Pages 146-156 of .NET Network programming show a asynchronous programming example, where some text is excahnged between a client and a server. I downloaded the code and compiled the files, and ran both asyncserver and asyncclient, to see the code in action. Only thing I get an exception everytime I run the client (assume the server is running). The server does get the text from the client, but when the server bounces the text back to the client, I get an exception w/ the client's EndReceive method. The key part of the message is that "connection was forcibly closed by the remote host." In the server code, after the send, it uses a Shutdown( SocketShutdown.Both ) followed by a Close() call. That seems ok. What appears to be happening is that when the client wants to receive the data, the server has already closed the connection, so an exception occurs, at least according to my understanding. I could be mistaken. I've tried "hacks" such as putting a thread here or there to sleep, but nothing seems to work. I even set the linger option of the server's socket to 5, so it hangs around presumably when close is called. But I still get the exception. Does that mean that the data transfers so fast that no data is seen in the network queue when close() is called (so the fact I set a linger option doesnt matter at that point), but the client cant use the connection b/c of the close() call. The only thing I've been able to do to get it to function is to change the socketoption to SocketShutdown.Recieve instead, and that makes it work.
Sorry for the long post, but I wanted to be thorough. Was the only way of getting it to work by changing the shutdown option? I mean, I guess I was expecting the code to work, but I know that isnt the case all the time. Has anyone else had the same problem on their computers? I guess that's all for now. Thanks for anyone that answers.