I have a client / server TCP application to communicate with a Windows CE device through an ActiveSync connection. Both the client and server use asynchronous sockets (i.e., the Socket.Begin* and Socket.End* ). When the client and server are running on my desktop, everything works exactly as expected, but when the client is running on a Windows CE device connected via ActiveSync, I always get a SocketException in ReceiveCallback after calling Socket.Shutdown (when the device initiates disconnection). Full exception:
System.Net.Sockets.SocketException: An error message cannot be displayed because an optional resource assembly containing it cannot be found at System.Net.Sockets.Socket.ReceiveNoCheck() at ReceiveAsyncRequest.doRequest() at AsyncRequest.handleRequest() at WorkerThread.doWork() at WorkerThread.doWorkI() at WorkItem.doWork() at System.Threading.Timer.ring()
Everything also works correctly if the server (running on the desktop) initiates a shutdown. I have a couple of ideas on how to avoid this, including banning disconnected devices and ignoring all exceptions after initiating a disconnection. However, I would like to know why this is happening, and if there is a better way to handle this.
Disable ReceiveCallbacks (operatively identical both on the server and on the client):
public bool Disconnect(StateObject state) { try{ if(state.isDisconnecting) return false; state.isDisconnecting = true; state.sock.Shutdown(SocketShutdown.Both);
source share