On Jan 4, 2013, at 17:38, Josh Santangelo wrote:
> I'm trying to build a simple server where multiple clients connect over TCP, and any message from a client is relayed to all the others. This isn't going to be used for a chat room, but it's basically the same idea.
>
> I tried building this with
socket.io but got stuck pretty quickly:
>
> var io = require('
socket.io').listen(81);
>
> console.log('foo');
> io.sockets.on('connect', function (socket) {
> console.log('connected...');
>
> socket.on('disconnect', function () {
> console.log('disconnected');
> });
> });
>
> I see "foo" trace out, and on the client side it looks like I'm connected, but "connected" and "disconnected" never trace out, so I'm guessing those event handlers aren't working for some reason.
>
> I'm not married to
socket.io, and actually using fewer modules would be better, but I'm surprised I couldn't find a code sample for this use case since it sounds like it's a pretty common node.js usage.
I got
socket.io working successfully following a few examples. It seems to be well-regarded and is probably a good place to start.
According to the documentation on
http://socket.io you want to listen for 'connection' (not 'connect').