Trilarion / imperialism-remake

Imperialism remake
https://remake.twelvepm.de/
GNU General Public License v3.0
53 stars 19 forks source link

How to connect server and clients if they are behind NATs? #31

Open Trilarion opened 6 years ago

Trilarion commented 6 years ago

I'm not an expert on this but it needs to be solved in order to allow multiplayer games.

The question is how two peers behind routers/network address translations discover and connect to each other? See for example: https://en.wikipedia.org/wiki/Network_address_translation#Type_of_NAT_and_NAT_traversal.2C_role_of_port_preservation_for_TCP

Trilarion commented 6 years ago

It seems port forwarding using UPnP/IDG might be the easiest possible solution if the router supports it.

See: https://stackoverflow.com/a/28652219/1536976

krs013 commented 6 years ago

I don't think this is something we need to worry about. As long as the program opens the port and maybe reports the port and IP address, we can leave the rest to the users. Works for Minecraft.

Trilarion commented 6 years ago

What tools do users of Minecraft use to implement port forwarding? If there are convenient tools out there, I agree that we don't need to do that ourselves. A little recipe for how to use them might be worth an entry in the FAQ.

Getting the public IP is actually something we do not have yet. The network code only delivers the local IP if behind a NAT. But there is for example ipgetter.

krs013 commented 6 years ago

I mean, I wouldn't go so far as to say that there are convenient tools... When I've set up servers I just set up ports at the router level since I run the network. Bigger servers are usually run on remote servers that have setup like that built in.

I guess I shouldn't talk about it like it's a solved problem, but it's something that many users can handle on their own, so I wouldn't worry about it for now. But if there's a way to do it with UPnP or something similar, and a use for that kind of mechanism in testing, it might be worth trying.

Trilarion commented 6 years ago

Okay. As a first step, I displayed the "real" IP address using ipgetter. The rest is for later.