Example #1
0
        public bool Handle(byte[] firstPacket, int length, Socket socket, object state)
        {
            if (socket.ProtocolType != ProtocolType.Udp)
            {
                return(false);
            }

            //?What feature ?
            if (length < 4)
            {
                return(false);
            }

            UDPState   udpState       = (UDPState)state;
            IPEndPoint remoteEndPoint = (IPEndPoint)udpState.RemoteEndPoint;

            UDPHandler handler = _cache.Get(remoteEndPoint);

            if (handler == null)
            {
                handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint), remoteEndPoint);
                _cache.Add(remoteEndPoint, handler);
            }

            handler.Send(firstPacket, length);
            handler.Receive();

            return(true);
        }
 public override bool Handle(byte[] firstPacket, int length, Socket socket, object state)
 {
     if (socket.ProtocolType != ProtocolType.Udp)
     {
         return false;
     }
     if (length < 4)
     {
         return false;
     }
     Listener.UDPState udpState = (Listener.UDPState)state;
     IPEndPoint remoteEndPoint = (IPEndPoint)udpState.remoteEndPoint;
     UDPHandler handler = _cache.get(remoteEndPoint);
     if (handler == null)
     {
         handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint), remoteEndPoint);
         _cache.add(remoteEndPoint, handler);
     }
     handler.Send(firstPacket, length);
     handler.Receive();
     return true;
 }
Example #3
0
        public bool Handle(byte[] firstPacket, int length, Socket socket, object state)
        {
            if (socket.ProtocolType != ProtocolType.Udp)
            {
                return(false);
            }
            if (length < 4)
            {
                return(false);
            }
            Listener.UDPState udpState       = (Listener.UDPState)state;
            IPEndPoint        remoteEndPoint = (IPEndPoint)udpState.remoteEndPoint;
            UDPHandler        handler        = _cache.get(remoteEndPoint);

            if (handler == null)
            {
                handler = new UDPHandler(socket, _config.GetCurrentServer(), remoteEndPoint);
                _cache.add(remoteEndPoint, handler);
            }
            handler.Send(firstPacket, length);
            handler.Receive();
            return(true);
        }
Example #4
0
        public override async Task <bool> Handle(Memory <byte> packet, Socket socket, EndPoint client)
        {
            if (socket.ProtocolType != ProtocolType.Udp)
            {
                return(false);
            }
            if (packet.Length < 4)
            {
                return(false);
            }
            IPEndPoint remoteEndPoint = (IPEndPoint)client;
            UDPHandler handler        = _cache.get(remoteEndPoint);

            if (handler == null)
            {
                handler = new UDPHandler(socket, _controller.GetAServer(IStrategyCallerType.UDP, remoteEndPoint, null /*TODO: fix this*/), remoteEndPoint);
                handler.Receive();
                _cache.add(remoteEndPoint, handler);
            }
            await handler.SendAsync(packet);

            return(true);
        }