LoveAndCoding
LoveAndCoding

Reputation: 7947

Socket.IO is not triggering the connect event

I'm trying to setup a Socket.IO server, and right now, connecting doesn't seem to be working the way it does in the Wiki. I'm connecting to a server using the namespace /client, and I'm successfully seeing the connection made in the debug log, but the connection message is never display (and the other contents are never getting attached).

Server-side

var clients = io
    .of('/client')
    .on('connect', function (socket) {
        // This is never getting run
        console.log('Client connected');
    });

Client side

var socket = io.connect('http://localhost:8082/client');

Why, in the above code, am I not getting the 'Client connected' message in my console?

Upvotes: 0

Views: 1727

Answers (1)

LoveAndCoding
LoveAndCoding

Reputation: 7947

So, turns out this is a very simple issue, as I suspected. The client uses the connect event, but the server uses connection.

The code should look like:

var clients = io
    .of('/client')
    .on('connection', function (socket) {
        // This is never getting run
        console.log('Client connected');
    });

Upvotes: 4

Related Questions