enet-p2p icon indicating copy to clipboard operation
enet-p2p copied to clipboard

Connecting fails with computers on LAN and external serve

Open ReaverTeknoGods opened this issue 1 year ago • 3 comments
trafficstars

Running the server on external ip (with port forwarded obviously) works fine with computers on different IP addresses. (networks)

Example: Server IP1 (Port forwarded) Client IP2 (Behind NAT) Client IP3 (Behind NAT) = WORKS

Not working example: Server IP1 (Port forwarded) Client IP2 (Behind same NAT) Client IP2 (Behind same NAT) = DOES NOT WORK

It fails to connect to the other peer on line: ENetPeer* peerRemote = enet_host_connect(host, &addr, 2, 0);

peerRemote->state is stuck at ENET_PEER_STATE_CONNECTING forever.

ReaverTeknoGods avatar Feb 16 '24 09:02 ReaverTeknoGods

There's a chance the router can see that a client from its network is trying to connect to itself and then not route it as expected. Perhaps a good solution would be to detect the case of being behind the same NAT and public IP address, and then route it through local IP addresses instead.

codecat avatar Feb 16 '24 14:02 codecat

What if there is 3 players on LAN 1 and 2 players on LAN 2?

ReaverTeknoGods avatar Feb 16 '24 16:02 ReaverTeknoGods

I guess that depends on your actual implementation of your game lobbies. You could pick one of those players as the host, then connections could be made in a directed manner.

codecat avatar Feb 18 '24 09:02 codecat