node.jssocketssocket.iolocalhostphonegap-desktop-app

Socket.io local network not connecting


Okay, I have the following setup: https://i.sstatic.net/4T9SX.jpg ( If image below is too small )

enter image description here

The problem is that Computer 2 can not connect with socket.io to computer 1.

enter image description here

Yes i included socket.io in computer 2:

enter image description here

Any ideas as to why Computer 2 cannot connect to computer 1 with socket.io whilst ping can?

Extra information: - Socket.io version 1.4.5 - Both computers are windows 10 - Computer 2 javascript is in Phonegap - Computer 2 connects via wi-fi, computer 1 via ethernet

Greetings

EDIT Code from client (computer 2, init is called upon start):

KerstAppHome.prototype.init = function(){
    var address = 'http://192.168.2.120:2017';
    console.log("Connecting to: " + address);
    this.socket = io.connect(address);
    this.socket.on('connect', this.proxy(function(){
        console.log("Connected to socket!");
        this.socketIsConnected = true;

        this.socket.on('disconnect', this.proxy(function(){
            console.log("Disconnected from socket!")
            this.socketIsConnected = false;
        }));
        this.socket.on('musicBlob', this.proxy(this.onMusicBlobReceived))
    }));

};

KerstAppHome.prototype.onMusicBlobReceived = function(musicBlob){
    console.log("RECEIVED SOMETHING");
    this.audioCtx.decodeAudioData(musicBlob).then(this.proxy(function(audioBuffer) {
        var source = this.audioCtx.createBufferSource();
        source.buffer = audioBuffer;
        source.connect(this.audioCtx.destination);
        source.start();
    }));
}

Code from server (computer 1):

var port = 2017;
var io = require('socket.io')(port);
console.log("Listening for socket connections on port " + port);

io.on('connection', function (socket) {
    console.log("Connection made!");
    socket.on('musicBlob', function(musicBlob){
        socket.broadcast.emit('musicBlob', musicBlob);
    });
});

Relevant code from browser ( computer 1 ):

var socket = io.connect('http://localhost:2017');
var socketIsConnected = false;

socket.on('connect', function(){
    console.log("Connected to server!");
    socketIsConnected = true;
});
socket.on('disconnect', function(){
    console.log("Disconnected from server!")
    $scope.socketIsConnected = false;
});

I want to know why computer 2 can't even connect to the server, The console.log("Connected to socket!"); is not even called

NOTE: If I execute the javascript of the client (computer 2) on computer 1, it works perfectly, makes connection and receives data!

NOTE: I tested it with computer 1 (server) his firewall turned off and it worked perfectly!


Solution

  • please check you firewall settings, or turn it off for few minutes and than try, also make sure both 2 computer should be connected with same lan/wifi. and

    allow phonegap, Evented I/O for v8 JavaScript and Secure Socket Tunneling Protocol through Windows Firewall,