I’ve coded a multiplayer ‘chat’ server as a precursor to writing a multiplayer game server. However I’m having some difficult design decisions.
-
If the server has multiple network interfaces, how to find the one with the internet connection. Currently I’m opening a port on each one. Suspect that this will do.
-
If the player is running the server behind a router, what is the best strategy to get port forwarding:
a) Detect private IP range on each interface. If none of the ethernet adapters have a public IP, display a warning about requiring port forwarding.
b) On each interface with a private IP range attempt to discover a Gateway using UPnP. When found, configure port forwarding. While there are libraries out there, they’re quite big. Also most DSL/Cable routers come with UPnP disabled for security reasons, so the effort might not be worth it. -
How do we determine the router WAN address & test that it works
a) Load the server from an external webserver using webstart. Dynamically generate the JNLP, so as to be able to pass arguments to the code. Pass REMOTE_ADDR & HTTP_X_FORWARDED_FOR, to allow the server code to ascertain the WAN address, even through a Proxy (Assuming the proxy is well behaved). The server code then attempts to open a (client) port on the WAN address to see if it can connect to its server port. This last step will only work if the router supports Loopback (i.e. you can access the WAN ip from behind the router).
b) As a), but to test the WAN IP, you access a port on the webserver, which has scripting to attempt to remotely access your server. This gets round the problem of testing whether port forwarding is set up on routers that don’t support Loopback. However it is more complicated. Are there any popular routers that are known not to do loopback, that make this worth the effort?
c) If we are doing UPnP discovery, we get ask the router directly for the WAN address. We will need this to tell the players where to go, but there is no real need to check the port forwarding, since we’ve configured it ourselves using UPnP.
d) We get the user to type in the WAN address. We then check access to it. -
How do we get the address of the server to the other players?
a) Have a dedicated server that is at a known location. Probably too expensive.
b) The first player starts the server manually, using webstart. The server contains an http server. It opens a browser window to that server using the WAN IP address. The loaded page tells the user to cut ‘n’ paste the URL & send it to his/her players. This only works if there is no router, or the router supports loopback. It is my favourite option though.
c) As b), but the page is opened on the server using the local IP, which should always work. The page provides the URL to provide to the players in the text of the page. -
How do we get the server IP into the client?
a) Each user has to type it in
b) The client is webstarted from the http page started on the server. The server can customise the JNLP served to pass the server IP as an argument. The loaded code can be on an external webserver to avoid overloading the limited bandwidth on the user’s server & to avoid multiple copies of the game cluttering up webstart. This only works if the JNLP can be on a different server to the application. I think this is the case. The client code must be signed as it must access an IP address different from that of it’s source server.
c) As b), but the main app is loaded from the game server. This part of the app contains the network code. The rest can be loaded as extensions from an external server.
d) Webstart the entire client from the web page loaded from the game server.
So… there are loads of options. Ideally I want the whole thing to need minimal user knowledge to work. However I don’t want to generate reams and reams of code. i.e. what is the minimum of webserver PHP support? How much effort should be put into the server to help users with their routers - e.g. is the UPnP code worth the effort, considering that most routers have it switched off by default?
Your views welcomed
Alan