Best way for networking if user starts a server

Hello,
I’m working on a xbattle variant for Android and Desktop. I’m using kryonet for the networking code. One user can start a server on his tablet/desktop/phone and all other players can connect to the server. Currently this works only for LAN/WLAN. The next step would be the internet, but I’m not sure which is the best solution.
I’m thinking of implementing a meta server where games are registered or using an existing framework, but this is only one part of the solution. If the user who started the server is behind a firewall, no one can connect. Another possibility would be to use the google multiplayer games services, to distribute the games messages (and hopefully avoiding the firewall problems). So if I don’t want a central server, what is the best solution?
Bye
Roland

24 years of experience and you’ve never heard of UPnP? ;P.

But really… Universal plug n’ play (UPnP).

The only thing stopping the players from connecting to a server over the internet is port forwarding. Since you don’t want to host servers, players will need to portforward.

UPnP is a good solution here, I recommend researching it.

I ran into the same problem a couple years ago. I wanted players to be able to host their own multiplayer games and be able to do it from a mobile device. You have a couple options here to do this…none of them perfect so you’ll have to weigh the pro’s and cons.

One way or another you’re going to have to use some type of central matchmaking server to allow players to find servers or each other. Here are a couple ways you can do it.

  1. This is way that most PC games run but probably won’t be much help for you. If a player wants to host a server they must be directly connected to the internet. There’s a lot of different names for it but ostensibly this means they’re either not behind a NAT or they’ve got some type of port forwarding setup. Also they don’t have a firewall blocking incoming packets. Your matchmaking server is pretty easy then. A player sets up a server, sends the details to the matchmaker, matchmaker at this point has the public ip address and port and can add it to the server list.

  2. In your case you want android players to host servers which mostly gets rid of any manual port forwarding options. No matter what, you’ll never get around the obstacle that the player hosting must be able to accept connections from clients. Here’s the sort of flow that I ended up coming up with.

Is the Host not behind a NAT or firewall -> Perfect! Any client can connect to them if they have the address:port.

Does the Host have UPnP supported? -> Perfect! Any client can connect to them if they have the address:port.

Is Host capable of UDP hole punchthrough? This depends on the host connection to the internet and can get very complicated. There’s some protocols out there that I’ve heard will do this for you (STUN, ICE) but it took me a few weeks before I understood enough to roll my own solution. It involves testing the host’s connection for NAT mapping and filtering type which in itself requires your matchmaker to have access to at least two or three separate IP addresses. Depending on the mapping type you might just quit there or try to guess what ip:port they’re going to use. When a player wants to connect to the host you’ll have to handle that sync as well. And depending on the router it might seem it’s going to work and then it just doesn’t. Does the host’s router support hairpinning? Did you test to see if the host and client are behind the same NAT. Is there an ISP level NAT involved? If the host is behind a NAT then both the host and the client needs to be capable of NAT punchthrough or they’ll need a proxy. You can try run the proxy over some other client that happened to have UPnP enabled. I mean this is just stuff off the top of my head, there’s a ton of edge cases and other issues involved. Before you go this route, realize it’s a huge pita.

In the end if none of the above works you’ve got to provide your own proxy fallback. You might as well have dedicated servers…

  1. The option I went with is just don’t let players host their own games. Linode and DigitalOcean VMs are cheap. For 10 bucks a month you can have a bunch of games setup yourself. If you want a solution that just works dedicated is the way to go. No worrying about cheating. No requiring your players to port forward or deal with UDP punchthrough issues. Since you don’t have to worry about hacked hosts you can setup global stats and other cool stuff.

  2. Google games services. Don’t have any experience with it but from what I understand all your players need to have Google+ accounts but it should handle all the peer to peer matchmaking. Not sure if it runs off a central proxy server or if one player is chosen to be a host. Also not sure if there’s a client for desktop or if it’s android only so that might be an issue for you.

Anyways, lots of info out there on this but hopefully this helped.