You'll want to capture the result of socket.io's .listen()
to setup server-side listeners:
server.listen(8001);
var ios = io.listen(server);
ios.sockets.on('connection', function(socket){
socket.emit('message', {'message': 'hello world'});
});
The sockets
object isn't a member of the socket.io
module itself, but of a listening instance of io.Manager()
.
In the post you linked, there's a typo in one of the snippets (under "Adding Socket.io"):
// ...
var io.listen(server);
I'd assume that was meant to be:
var io = io.listen(server);