A question about closing socket
-
Hello , I am testing a very simple client/server socket application, using an asynchronous socket model. When I am closing a connection on behalf of client side, I am first calling the Shutdown(..both) method on the socket and then the Close () method. I am expecting a zero-length packet received on the server side , to signal the connection closing on the client side,and after this I call the Close () on the socket on the server side. The truth is, I receive more than one zero-length packet on the server when I shut down the connection on the client side . Why does it happen ? And how can it be since on the first zero-length packet I receive on the server , I close the server socket and no more packets should be received anymore ?
-
Hello , I am testing a very simple client/server socket application, using an asynchronous socket model. When I am closing a connection on behalf of client side, I am first calling the Shutdown(..both) method on the socket and then the Close () method. I am expecting a zero-length packet received on the server side , to signal the connection closing on the client side,and after this I call the Close () on the socket on the server side. The truth is, I receive more than one zero-length packet on the server when I shut down the connection on the client side . Why does it happen ? And how can it be since on the first zero-length packet I receive on the server , I close the server socket and no more packets should be received anymore ?
Closing a socket basically means that you will not use that socket for sending anymore. So you can still receive on it. This is why it is called a half close. Don't know why you see more than one zero packet sizes. This should occur only once because it is an indication that the peer side has closed its connection.
-
Closing a socket basically means that you will not use that socket for sending anymore. So you can still receive on it. This is why it is called a half close. Don't know why you see more than one zero packet sizes. This should occur only once because it is an indication that the peer side has closed its connection.
Thank you Philip, by now I think I have found the problem.... probably it was caused by the fact that , inadvertedly, I was calling beginReceive() more than once, before calling the corresponding endReceive() for each beginReceive() . In effect as I fixed this error it seems it doesn't happen anymore. Thank you anyway for your support. Leo