Hey folks,

I’ve been developing on multiplayer game called Drag’n Slay on at least 4 different locations and it’s been a pain in the ass to change the ip address on the backend-server web and unity android client and unity editor client everytime manually so they will connect to the socket.io (tcp) and diagram (udp) server.

So had an idea. What if I could let the clients connect to my already payed webserver and get the fixed but changing ip.
I figured it would require a couple of steps to do so:

1) load ftp credentials from a git-ignored file
2) figuring out the lan and wan ip address
3) creating a php script that respond a json object with the accessable ip addresses to the server
4) uploading the php script to my always accessable webserver
5) loading the json file on the clients and connect to the server by using the dynamic ip address

1) [node] reading credentials

the credentials.txt:

2. [node] getting the ip address is quite easy with os.networkInterfaces()

3. [node] dynamically creating the script that will respond the ip addresses respectively Important: In order to allow cross domain loading of the json object set Access-Control-Allow-Origin: *

I also made a short link to my node.js webserver default website:

4. [node] uploading the ip address to the server by using jsftp

5. [web-client] and finally using jquery connect to node.js socket.io with the dynamic ip

[android client] one way to receive the url on your android client is by using an async task; grab the ip whenever you need it (e.g. in your onCreate-activity method)

convinient call back method:

and you you’ll need a json parser