G
Guest
I have a .NET 2.0 application that acts as a TCP/IP server, and I’ve
discovered an issue with NetworkStream. I’ve accepted a client socket and
called steam.BeginRead(…) and my AsyncCallback has been called, so it calls
EndRead. EndRead occasionally throws an IoException that has an
InnerException of SocketException that has a SocketErrorCode of
OperationAborted. The MSDN documentation says that OperationAborted means
the socket is closed, and the socket’s IsConnected does indeed indicate false.
But I handle the exception and call stream.BeginRead(..) again and it works
fine and I continue to have a conversation with my client like nothing ever
happened. The client sends me a message every 15 seconds, and I reply OK.
Additionally, I have a 1 second timer and I can continue to send unsolicited
messages to the client every second.
Running in the debugger, I notice that I always get an Output Window message
of “The thread 0x1234 has exited with code 0 (0x0).†just before I get the
exception with the OperationAborted. I’m not terminating any threads in my
code.
Why does EndRead throw that exception that indicates OperationAborted?
How should I handle this exception? I could close the socket, but that
basically means that my application isn’t servicing clients.
Why is the NetworkStream and the Socket still connected and working?
Thanks,
John
discovered an issue with NetworkStream. I’ve accepted a client socket and
called steam.BeginRead(…) and my AsyncCallback has been called, so it calls
EndRead. EndRead occasionally throws an IoException that has an
InnerException of SocketException that has a SocketErrorCode of
OperationAborted. The MSDN documentation says that OperationAborted means
the socket is closed, and the socket’s IsConnected does indeed indicate false.
But I handle the exception and call stream.BeginRead(..) again and it works
fine and I continue to have a conversation with my client like nothing ever
happened. The client sends me a message every 15 seconds, and I reply OK.
Additionally, I have a 1 second timer and I can continue to send unsolicited
messages to the client every second.
Running in the debugger, I notice that I always get an Output Window message
of “The thread 0x1234 has exited with code 0 (0x0).†just before I get the
exception with the OperationAborted. I’m not terminating any threads in my
code.
Why does EndRead throw that exception that indicates OperationAborted?
How should I handle this exception? I could close the socket, but that
basically means that my application isn’t servicing clients.
Why is the NetworkStream and the Socket still connected and working?
Thanks,
John