Ejemplo n.º 1
0
 public void Stop()
 {
     Log.I("stop");
     GlobalEventLoop.Instance().RemoveSocket(UdpSocket);
     if (!UdpSocket.Connected)
     {
         return;
     }
     UdpSocket.Disconnect(false);
     UdpSocket.Close();
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 public void Start()
 {
     Log.I("register self to event loop");
     GlobalEventLoop.Instance().AddSocket(UdpSocket, OnUdpRead, null, OnUdpError);
 }