lucaspoffo / renet

Server/Client network library for multiplayer games with authentication and connection management made with Rust
Apache License 2.0
624 stars 67 forks source link

Document hosting behind port-forwarded NAT #45

Open Alainx277 opened 1 year ago

Alainx277 commented 1 year ago

Hosting behind a NAT router requires passing a different public IP to the server config and the socket. This is not visible in the examples or anything I had read. Doing this incorrectly causes no connections to go through, with no warnings.

Maybe there could be a comment in the examples. Above the line that builds the server config would be a good place in my opininon.

Original issue

I originally wanted to write a feature request, then realized it was already possible, just not very clear.

Original Text The IP a server listens on must match the one a client connects to. This prevents hosting behind a NAT device (like a home router), as the server can't bind on the public IP of the entire network. Hosting with port forwarding from home is a common thing when playing games with friends. I personally need it for testing my game from my personal computer.
lucaspoffo commented 1 year ago

Public address configuration seems to be a recurring cause of confusion. Adding some common scenarios in the readme or the doc should help, especially about NAT, port-forwarding, dedicated server... Maybe also add some external resources about it, but don't know which one.

sethquantix commented 1 year ago

I met this exact issue a few days ago. What exactly is the point of the NoHost error ? matching IP address once you're connected to an UDP socket doesn't make a lot of sense to me. Is it only for the Authentication side of things ?

Edit: So I went back digging into the RenetClient code. This problem only really occurs when you use Unsecure authentication, because you can only provide the one server address you use. I'm testing the connection over both local, LAN, and internet. So 3 different addresses (potentially). With secure authentication, it kinda goes away if you go through the hassle of setting up your external IP on the server configuration, but you might not know that (thinking aws hosting or similar. Plus it's way easier to just setup the server on 127.0.0.1 and proxy forward the traffic).