Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Socket.IO client 'unhandled socket.io url'

I'm attempting to have a node.js client communicate with a node.js server using Socket.IO, according to the documentation this should be pretty easy however I'm just getting a message 'info - unhandled socket.io url' on the server whenever the clients tries to connect to the server. Here is a very basic example from the root:


in a directory I installed the necessary Socket.IO modules using:

npm install socket.io socket.io-client

in a file servernode.js I put:

var app = require('http').createServer(), io = require('socket.io').listen(app);
io.sockets.on('connection', function(socket) {
   console.log('connected');
});
app.listen(60000);

in another file clientnode.js I put:

var socket = require('socket.io-client')('http://localhost:60000');
socket.on('connect', function(){
     console.log('socket connected.');
});

in two terminals I put

node servernode.js

and

node clientnode.js

Then in the server I get this message repeated ad infinitum:

 info - unhandled socket.io url

I've searched for this message and from what I could gather, it was related to differences between versions, but I suppose npm has those modules synched, no? In desperation I also tried getting the file from the server module at './node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js' (and using .connect - somehow in this version it's necessary) but then I get another error:

/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:1877
var port = global.location.port ||
                          ^
TypeError: Cannot read property 'port' of undefined
at Socket.isXDomain (/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:1877:31)
at Socket.handshake (/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:1627:14)
at Socket.connect (/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:1699:10)
at new Socket (/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:1551:12)
at Object.io.connect (/home/work/node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js:94:16)
at Object.<anonymous> (/home/work/testnode2.js:1:160)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)

Can anyone help me out with this?

like image 270
Gill Avatar asked Mar 17 '14 00:03

Gill


People also ask

How do I run a Socket.IO in node JS?

In order to do it, you need to create an index. js file and install socket.io and express. You can use the following command: touch index. js && npm install express socket.io && npm install --save-dev nodemon .

What is the difference between Socket.IO and socket IO client?

socket-io. client is the code for the client-side implementation of socket.io. That code may be used either by a browser client or by a server process that is initiating a socket.io connection to some other server (thus playing the client-side role in a socket.io connection).


1 Answers

Try using a newer version of socket.io, it worked for me.

npm install [email protected]
like image 182
idleherb Avatar answered Oct 03 '22 21:10

idleherb