public unsafe void Deal(SimpleUdpServce socket, EndPoint remote, byte[] buffer, int offset) { fixed(byte *c = buffer) { Deal(socket, remote, *(T *)(c + offset)); } }
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"); } }
protected override void Deal(SimpleUdpServce socket, EndPoint remote, ResNat value) { if (value.Equal(ResNat.NO_SERVER_FOUND)) { TestLog.Log("server not found"); } else if (value.Equal(ResNat.SUCCESS)) { TestLog.Log("nat success"); } }
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); }
protected abstract void Deal(SimpleUdpServce socket, EndPoint remote, T value);
protected override void Deal(SimpleUdpServce socket, EndPoint remote, ResAsServer value) { TestLog.Log($"outer ip::{value.address.toEndPoint()}"); }