Error while running an Asynchronous Server/Client

Im running a simple Server/Client application using TcpListener and TcpClient for (asynchronous) connecting and NetworkStream for asynchrous sending and recieving.

When i try to terminate a client, the server and all other clients crash and give this exception:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

" at System.Net.UnsafeNclNativeMethods.OSSOCK.WSAGetOverlappedResult(SafeCloseSocket socketHandle, IntPtr overlapped, UInt32& bytesTransferred, Boolean wait, IntPtr ignored)\r\n at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)\r\n at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)"

I dont mind that the connection crashes, but it should crash the whole server. I think the exception occures in the thread of the asynchronous begin/endread methods of the networkstream, alltought i have no clue on how to be sure. Does anybody know how to solve this exception or catch it so that the server and/or clients dont crash

All help appreciated...



Answer this question

Error while running an Asynchronous Server/Client