public static GetLocalIp ( bool preferIPv4 = false ) : string | ||
preferIPv4 | bool | |
Результат | string |
public void SendNatIntroduceRequest(IPEndPoint masterServerEndPoint, string additionalInfo) { //prepare outgoing data NetDataWriter dw = new NetDataWriter(); string networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv4); if (string.IsNullOrEmpty(networkIp)) { networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv6); } IPEndPoint localEndPoint = NetUtils.MakeEndPoint(networkIp, _socket.LocalPort); dw.Put((byte)PacketProperty.NatIntroductionRequest); dw.Put(localEndPoint); dw.Put(additionalInfo, MaxTokenLength); // Get Internet IP var publicIp = NetUtils.GetPublicIPAddress(); IPEndPoint internetEndpoint = NetUtils.MakeEndPoint(publicIp, 0); dw.Put(internetEndpoint); // //prepare packet SocketError errorCode = 0; _socket.SendTo(dw.Data, 0, dw.Length, masterServerEndPoint, ref errorCode); }
public void SendNatIntroduceRequest(NetEndPoint masterServerEndPoint, string additionalInfo) { if (!_netBase.IsRunning) { return; } //prepare outgoing data NetDataWriter dw = new NetDataWriter(); string networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv4); if (string.IsNullOrEmpty(networkIp)) { networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv6); } int networkPort = _netBase.LocalPort; NetEndPoint localEndPoint = new NetEndPoint(networkIp, networkPort); dw.Put(localEndPoint); dw.Put(additionalInfo, MaxTokenLength); //prepare packet var packet = _netBase.NetPacketPool.GetWithData(PacketProperty.NatIntroductionRequest, dw); _netBase.SendRawAndRecycle(packet, masterServerEndPoint); }
public void SendNatIntroduceRequest(IPEndPoint masterServerEndPoint, string additionalInfo) { //prepare outgoing data string networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv4); if (string.IsNullOrEmpty(networkIp)) { networkIp = NetUtils.GetLocalIp(LocalAddrType.IPv6); } Send( new NatIntroduceRequestPacket { Internal = NetUtils.MakeEndPoint(networkIp, _socket.LocalPort), Token = additionalInfo }, masterServerEndPoint); }
public void SendNatIntroduceRequest(NetEndPoint masterServerEndPoint, string additionalInfo) { if (!_netBase.IsRunning) { return; } //prepare outgoing data NetDataWriter dw = new NetDataWriter(); string networkIp = NetUtils.GetLocalIp(true); int networkPort = _netBase.LocalEndPoint.Port; NetEndPoint localEndPoint = new NetEndPoint(networkIp, networkPort); dw.Put(localEndPoint); dw.Put(additionalInfo, MaxTokenLength); //prepare packet _netBase.SendRaw(NetPacket.CreateRawPacket(PacketProperty.NatIntroductionRequest, dw), masterServerEndPoint); }