Socket.io connection url?

Solution 1:

As of Socket.io version 1, resource has been replaced by path. Use :

var socket = io('http://localhost', {path: '/nodejs/socket.io'});

See: http://blog.seafuj.com/migrating-to-socketio-1-0

Solution 2:

you can specify resource like this:

var socket = io.connect('http://localhost', {resource: 'nodejs'});

by default resource = "socket.io"

Solution 3:

If you are using express with nodejs:

Server side:

var io = require('socket.io')(server, {path: '/octagon/socket.io'});

then

io.on('connection', function(socket) {
        console.log('a user connected, id ' + socket.id);
        socket.on('disconnect', function() {
            console.log('a user disconnected, id '  + socket.id);
        })
})
socket.on('publish message ' + clientId, function(msg) {
        console.log('got message')
    })

Client side:

var socket = io('https://dev.octagon.com:8443', {path: '/octagon/socket.io'})

then

socket.emit('publish message ' + clientId, msg)

Solution 4:

I use below approach to achieve this goal:

client side:

var socket = io.connect('http://localhost:8183/?clientId='+clientId,{"force new connection":true});

server side:

var io = require('socket.io').listen(server);
io.sockets.on('connection', function(socket) {
    console.log("url"+socket.handshake.url);
    clientId=socket.handshake.query.clientId;
    console.log("connected clientId:"+clientId);

});

reference:https://github.com/LearnBoost/socket.io/wiki/Authorizing#global-authorization