0
votes

I am able to run my node.js server, my phaser.js game runs but I get no 'connected' console.log when the game runs. I instead get this error message from the client end:

enter image description here

socket.io-1.4.5.js:1 GET http://192.168.128.184:8080/socket.io/?EIO=3&transport=polling&t=LdMR6Ro net::ERR_CONNECTION_REFUSED

SERVER:

var serverPort = 8080;

console.log("Initializing Server.");

var express = require('express');
var connect = require('connect');
var app = express();
var serv = require('http').Server(app);  //.createServer(app);
var io = require('socket.io').listen(serv);  //(serv,{});

console.log("Starting Server.");

var serveStatic = require('serve-static');
connect().use(serveStatic(__dirname)).listen(serverPort, function(){
    console.log('Server running on ' + serverPort + ' !');
});

app.get('/',function(req, res) {
    res.sendFile(__dirname + '/index.html');
});

serv.listen(8081);

var SOCKET_LIST = {};
io.on('connection',function(socket){  
    console.log("A user is connected");
});

io.sockets.on('connection', function(socket){
    console.log('Socket connection');
});

CLIENT

var local = "http://" + document.location.host + ":8081";
        var socket = io().connect(local);
1

1 Answers

2
votes

In your client code you are using io().connect(local) however the correct way to connect using a specified address with your variable is io.connect(local).

Also, document.location.host will include ":8080" if it is a part of the address you used to obtain the page, therefore you need to remove it. You can try something like document.location.host.split(':')[0]