开发者

Does this Socket.IO code create a blocked connection?

开发者 https://www.devze.com 2023-03-20 02:08 出处:网络
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.

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'.

0

精彩评论

暂无评论...
验证码 换一张
取 消