C# Service No SocketException
-
Hi all, I am starting a C# Windows Service. In the Service class, I've added an object to the service class, and OnStart, I initialize this object which creates a socket listener. I use Asynchronous Sockets. So BeginAccept/EndAccept and BeginReceive/EndReceive is used. My client app connects fine to the server and disconnects fine, but on the server end, the server doesn't recognize the client disconnection. I receive a OnDataReceived message, which then triggers the EndReceive. I have a sample client-server application that does exactly the same thing, which I've cut-n-pasted from. In the sample, the EndReceive throws a SocketException with the error code 10054 (disconnection). But in my code, the EndReceive just returns 0 bytes received, and no exception is thrown. Can anyone point me in the right direction? Cheers, "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)
-
Hi all, I am starting a C# Windows Service. In the Service class, I've added an object to the service class, and OnStart, I initialize this object which creates a socket listener. I use Asynchronous Sockets. So BeginAccept/EndAccept and BeginReceive/EndReceive is used. My client app connects fine to the server and disconnects fine, but on the server end, the server doesn't recognize the client disconnection. I receive a OnDataReceived message, which then triggers the EndReceive. I have a sample client-server application that does exactly the same thing, which I've cut-n-pasted from. In the sample, the EndReceive throws a SocketException with the error code 10054 (disconnection). But in my code, the EndReceive just returns 0 bytes received, and no exception is thrown. Can anyone point me in the right direction? Cheers, "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)
I think that's the expected behavior, according to the MSDN documentation. " If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes". You can therefore assume that if you get 0 bytes received in EndReceive, the remote client has disconnected. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
I think that's the expected behavior, according to the MSDN documentation. " If the remote host shuts down the Socket connection with the Shutdown method, and all available data has been received, the EndReceive method will complete immediately and return zero bytes". You can therefore assume that if you get 0 bytes received in EndReceive, the remote client has disconnected. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
Thanks Senthil, I didn't see that in the documentation. Much appreciated. Jub "If you're too careful, your whole life can become a f---in' grind." - Mike McD (Rounders)