public void Stop() { Log.I("stop"); GlobalEventLoop.Instance().RemoveSocket(UdpSocket); if (!UdpSocket.Connected) { return; } UdpSocket.Disconnect(false); UdpSocket.Close(); }
TransportLayer() { Log.Name = "TransportLayer"; var localAddress = Utils.DetectHost(); if (localAddress == null) { throw new SocketException(); } RawSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp); RawSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, false); RawSocket.Bind(new IPEndPoint(localAddress, 0)); RawSocket.IOControl(IOControlCode.ReceiveAll, new byte[] { 1, 0, 0, 0 }, new byte[] { 1, 0, 0, 0 }); GlobalEventLoop.Instance().AddSocket(RawSocket, OnRawRead, null, OnRawError); }
public void Start() { Log.I("register self to event loop"); GlobalEventLoop.Instance().AddSocket(UdpSocket, OnUdpRead, null, OnUdpError); }