Eliezer Broide Eliezer Broide - 5 months ago 40
Javascript Question

Mobile Phonegap applications on a local network

I've created a game using html5 and websockets that is played with both a pc and a mobile device (multiple mobile devices can also be played):

The game has a Stage - The PC or a tablet device.

And several players — Other mobile devices

The current connection between the Stage and Players is with a number (the Stage shows a number and a player can join through that number), however, I'm searching for a way that the Players can join just by being in the same local network as the Stage - meaning auto-discovery through a local network.

I've been searching WebRTC and other p2p solutions but I can't find anything. Is there something else I can use or is it completely impossible?


There's no javascript only way to the local ip address from inside a browser. There do seem to be a good number of cordova/phonegap plugins that purport to do this:

http://plugreg.com/plugin/weconstudio-it/phonegap-plugin-ipaddress https://github.com/jcesarmobile/my-phonegap-plugins/tree/master/iOS/NetworkInterfacesPlugin

As well as the one pointed out in the comment above. It looks like it's either android or IOS. Someone should write one that works on both!

If it was me. I would probably work with the browser headers on the Stage: REMOTE_ADDR, HTTP_CLIENT_IP, etc. There are some fine points to doing this: http://roshanbh.com.np/2007/12/getting-real-ip-address-in-php.html

On a local network, you'll be able to get the real IP address of each device. Private networks fall into a particular address space:        -      -     -

So your Stage will know when its clients are connecting to it on a LAN. Does that get you where you need to go?