private void OnReceive(IAsyncResult ar) { try { IPEndPoint remote = new IPEndPoint(IPAddress.Any, 0); byte[] data = fSocket.EndReceive(ar, ref remote); DatagramPacket packet = new DatagramPacket(data, remote); fLastIncomingPacket = new IncomingUDPClientPacket(this, packet, fLastIncomingPacket); fSocket.BeginReceive(OnReceive, null); } catch (Exception ex) { } }
/// <summary> /// Start the udp connector. /// </summary> public void Start() { if (!fActive) { try { fActive = true; try { fSocket = new UdpClient(0); } catch (SocketException ex) { fActive = false; throw ex; } fLastIncomingPacket = null; fLastOutgoingPacket = null; if (fReadTimeOut > 0) { /*fSocket.SendTimeout = fReadTimeOut; * fSocket.ReceiveTimeout = fReadTimeOut;*/ } try { fSocket.BeginReceive(new AsyncCallback(OnReceive), null); } catch (Exception ex) { throw ex; } } catch (SocketException ex) { Stop(); throw ex; } } }