0

Currently I develop a little multiplayer Browsergame with NodeJs and looking for possibilities to run the Server on Android. This would be nice to make Lan-Parties possible.

Due to my lack of Java experiences a solution for Phonegap or any likely ready to go tools would be nice but is no must.

Steffomio
  • 356
  • 3
  • 6
  • 1
    http://stackoverflow.com/questions/36632649/running-node-js-on-android and other information on this can be found by searching `nodejs android` in your favorite search engine. – CommonsWare Dec 12 '16 at 18:09

1 Answers1

0

For android you have to edit cordova.xml and add access to the socketio host:

<access origin="HOST*"/> 

index.html (with socketio example):

<script src="HOST/socket.io/socket.io.js"></script>
<script>
    var socket = io.connect('HOST');
    socket.on('news', function (data) {
        socket.emit('my other event', { my: 'data' });
    });
</script>

app.js (server side javascript / basic socketio example):

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {

socket.emit('news', { hello: 'world' });
    socket.on('my other event', function (data) {
        console.log(data);
    });
});

The HOST you have to replace with hostname of your socket.io server!

Hassan ALi
  • 1,313
  • 1
  • 23
  • 51