I have written an async UDP client to talk to a server at my company. When I run on my developer machine all is well. When I deploy to another machine I get a socket exception on EndReceive the first time I send data over the socket. My dev box is Win7 and I have deployed to both an XP SP3 machine and a Server 2003 R2 machine. Below is the receive code:
Private Sub ReceiveCallback(ByVal ar As IAsyncResult)
Try
' Retrieve the state object and the client socket
from the asynchronous state object.'
Dim state As StateObj = CType(ar.AsyncState, StateObj)
Dim client As Socket = state.sockArg
' Read data from the remote device.'
Dim bytesRead As Integer
receiveDone.WaitOne(Timeout.Infinite)
bytesRead = client.EndReceive(ar)
If bytesRead > 0 Then
Dim s As String = Encoding.ASCII.GetString(state.buffer, 0, bytesRead)
parsedata(s)
End If
Catch SockEx As SocketException
mlog.Error(String.Format("ID={1} {0} SocketError={2}", SockEx.Message, ID.ToString, SockEx.SocketErrorCode.ToString), SockEx)
Catch ox As System.ObjectDisposedException
mlog.Warn(String.Format("Object Disposed ID={0}", ID.ToString))
Catch ex As Exception
mlog.Error(String.Format("{1} ID={0}", ID.ToString, ex.Message), ex)
End Try
End Sub 'ReceiveCallback
The exception I get is:
System.Net.Sockets.SocketException: The I/O operation has been aborted because of either a thread exit or an application request at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at RTSPc.Connection.ReceiveCallback(IAsyncResult ar)
The SocketException is OperationAborted