public void OnDataReceived(IAsyncResult asyn) { // Logger.Log(0, "Begin OnDataReceived"); IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); byte[] buf = null; try { buf = udpConn.EndReceive(asyn, ref remoteIpEndPoint); } catch (SocketException e) { if (e.SocketErrorCode == SocketError.Interrupted) { // ignore return; } log_status.WarnFormat("Caught socket exception: {0}", e); WaitForData(); return; } catch (ObjectDisposedException) { // just ignore this one return; } RdpConnection conn = GetConnection(remoteIpEndPoint); if (conn == null) { log_status.Info("Handling new connection"); conn = HandleNewConnection(remoteIpEndPoint); } if (conn != null) { RdpPacket packet = new RdpPacket(buf); // Logger.Log(0, "Got data in OnDataReceived"); conn.OnSegmentArrival(packet, remoteIpEndPoint); // Logger.Log(0, "Done with OnDataReceived"); } try { WaitForData(); } catch (SocketException e) { if (e.SocketErrorCode != SocketError.Interrupted) { throw; } } catch (ObjectDisposedException) { // Just ignore this } }