LiteNetLib icon indicating copy to clipboard operation
LiteNetLib copied to clipboard

Unity : Error when trying to connect to Nat server.

Open Bradsama opened this issue 3 years ago • 4 comments

So my script is identical to setting up a client to connect to a Nat Punch server. But each time I start the project with the script attached to a gameobject I keep getting this error.

[S]System.Net.Sockets.SocketException (0x80004005): The system detected an invalid pointer address in attempting to use a pointer argument in a call.

UnityEngine.Debug:Log (object) LiteNetLib.NetDebug:WriteLogic (LiteNetLib.NetLogLevel,string,object[]) (at Assets/LiteNetLib/NetDebug.cs:51) LiteNetLib.NetDebug:WriteError (string,object[]) (at Assets/LiteNetLib/NetDebug.cs:89) LiteNetLib.NetSocket:SendTo (byte[],int,int,System.Net.IPEndPoint,System.Net.Sockets.SocketError&) (at Assets/LiteNetLib/NetSocket.cs:507) LiteNetLib.NatPunchModule:Send<LiteNetLib.NatPunchModule/NatIntroduceRequestPacket> (LiteNetLib.NatPunchModule/NatIntroduceRequestPacket,System.Net.IPEndPoint) (at Assets/LiteNetLib/NatPunchModule.cs:116) LiteNetLib.NatPunchModule:SendNatIntroduceRequest (System.Net.IPEndPoint,string) (at Assets/LiteNetLib/NatPunchModule.cs:181) LiteNetLib.NatPunchModule:SendNatIntroduceRequest (string,int,string) (at Assets/LiteNetLib/NatPunchModule.cs:169) NatClient:Start () (at Assets/NatClient.cs:29)

The line it's pointing to is this using my dns host name from duckdns and set to my servers ip.

client.NatPunchModule.SendNatIntroduceRequest("trdm.duckdns.org", 8500, "token1");

Any idea on what to do to get this working?

Bradsama avatar Mar 06 '21 00:03 Bradsama

@Bradsama maybe you trying resolve IPv6 address in IPv4 context or vice versa. Try resolve IP of "trdm.duckdns.org" in separate call using ResolveAddress(string hostStr, AddressFamily addressFamily) in NetUtils

RevenantX avatar Mar 10 '21 23:03 RevenantX

Hmm well I have tried this even with the server on local using the loopback address and get this same error.

But I'll try using this within NetUtils.

Bradsama avatar Mar 11 '21 00:03 Bradsama

Getting the same error message using this too. Works fine outside of Unity within a client program on it's own so I'm not sure what is going on.

Bradsama avatar Mar 11 '21 03:03 Bradsama

I solved the problem with this method,but I dont know why they dont support ipv6 in this mode.

    client = new NetManager(listener)
    {
        //IPv6Enabled = IPv6Mode.DualMode,
        NatPunchEnabled = true
    };

WarrenMondeville avatar Aug 25 '21 13:08 WarrenMondeville