The general rule in writing Node.js code is that all code should be non-blocking and communicate via events. I would like to know if this code written using the S开发者_C百科ocket.IO library for Node.js create a blocked connection, or does it follow the general Node.js rules?
sio.sockets.on('connection', function (socket) {
socket.on('message', function (msg) {
console.log("Received message"+message);
});
socket.on('cookie', function (msg) {
console.log("Cookie Received");
console.log(msg);
});
this.send('hello');
socket.on('disconnect', function (){
console.log('Disconnected');
});
});
Would be grateful for any help.
no, node.js socket.io server listens tcp with standard node non-blocking api
That is, your control goes immediately to next statement after sio.sockets.on(..);
, the only thing happen in this call is 'construct javascript function object abd assign to listeners array'.
精彩评论