webSocketServer node.js how to differentiate clients

后端 未结 10 2014
[愿得一人]
[愿得一人] 2020-12-22 19:36

I am trying to use sockets with node.js, I succeded but I don\'t know how to differentiate clients in my code. The part concerning sockets is this:

var WebSo         


        
10条回答
  •  [愿得一人]
    2020-12-22 20:33

    By clients if you mean the open connections, then you can use ws.upgradeReq.headers['sec-websocket-key'] as the identifier. And keep all socket objects in an array.

    But if you want to identify your user then you'll need to add user specific data to socket object.

提交回复
热议问题