Connect to Socket.IO server with specific path and namespace

On your server, don’t forget to specify the path as well:

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

io
.of('/my-namespace')
.on('connection', function(socket){
    console.log('a user connected with id %s', socket.id);

    socket.on('my-message', function (data) {
        io.of('my-namespace').emit('my-message', data);
        // or socket.emit(...)
        console.log('broadcasting my-message', data);
    });
});

On your client, don’t confuse namespace and path:

var socket = io('http://www.example.com/my-namespace', { path: '/myapp/socket.io'});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)