Dynamicly updating local ip address of Node.js server with Node.js

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 (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 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

Playing with Node.js and MongoDB

Well i’ve been playing a little with Node.js and MongoDB. To get MongoDB running you need to install MongoDB. There are several node plugins, I like mongoskin. (…work in progress)