/// <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; } } }
/// <summary> /// Send data to host. /// </summary> /// <param name="bytes">The byte array to be send.</param> /// <param name="offset">The position in the data buffer at witch to begin sending.</param> /// <param name="length">The number of the bytes to be send.</param> public void SendData(byte[] bytes, int offset, int length) { DatagramPacket outPacket = new DatagramPacket(bytes, offset, length, fServerEndPoint); fLastOutgoingPacket = new OutgoingUDPClientPacket(this, outPacket, fLastOutgoingPacket); }