Ejemplo n.º 1
0
 protected override void Deal(SimpleUdpServce socket, EndPoint remote, ReqNat value)
 {
     TestLog.Log($"ReqNatServerDealer recv");
     if (env.value == EnvEnum.Center)
     {
         if (!server.tryGet(value.address, out var endp))
         {
             TestLog.Log($"nat ip::{endp} not found");
             socket.Send(ResNat.NO_SERVER_FOUND, remote);
         }
         else
         {
             TestLog.Log($"server ip::{endp} client id::{remote}");
             var remoteAddr = remote.ValueAddress();
             //if (remoteAddr.ipaddress == value.address.ipaddress)
             //    remoteAddr.ipaddress = ValueAddress.LocalAddr;
             socket.Send(new ReqNat {
                 address = remoteAddr
             }, endp);
         }
     }
     if (env.value == EnvEnum.Server)
     {
         var endp = value.address.toEndPoint();
         TestLog.Log($"nat start watting ip = {endp}");
         //using(Socket natSocket=new Socket(AddressFamily.InterNetwork,SocketType.Dgram, ProtocolType.Udp))
         //{
         //    natSocket.Bind(new IPEndPoint(IPAddress.Any, value.address.port));
         //    natSocket.SendTo(ResNat.SUCCESS.ToByteArray(), endp);
         //}
         //socket.remoteEnd = endp;
         socket.Send(ResNat.SUCCESS, endp);
         TestLog.Log($"nat end");
     }
 }
Ejemplo n.º 2
0
        protected override void Deal(SimpleUdpServce socket, EndPoint remote, ReqAsServer value)
        {
            var v = remote.ValueAddress();

            if (!server.Contains(v))
            {
                server.Add(v, remote);
            }
            TestLog.Log($"server ip::{remote}");
            socket.Send(new ResAsServer()
            {
                address = v
            }, remote);
        }