How to uniquely identify a socket with Node.js

后端 未结 7 1887
时光说笑
时光说笑 2020-12-10 01:25

TLDR; How to identify sockets in event based programming model.

I am just starting up with node.js , in the past i have done most of my coding part in C++ and PHP s

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 02:24

    In c++ to identify a socket we could have done something like writing a main socket say server to listen for new connections and then handling those connections accordingly.but so far i havent found anything like that in node.js . (the berkeley socket model) Does it even exist in node.js .. if not i am going back to my C++ :$

    You should go back, because JavaScript is a prototype-based, object-oriented scripting language that is dynamic, weakly typed and has first-class functions. They are both completely different languages and you will have to have a different mindset to write clean JavaScript code.

    https://github.com/LearnBoost/Socket.IO/wiki/Migrating-0.6-to-0.7

    Session ID

    If you made use of the sessionId property of socket in v0.6, this is now simply .id.

    // v0.6.x
    var sid = socket.sessionId;
    
    // v0.7.x
    var sid = socket.id;
    

提交回复
热议问题