Sending message to a specific connected users using webSocket?

后端 未结 5 2130
Happy的楠姐
Happy的楠姐 2020-11-29 15:43

I wrote a code for broadcasting a message to all users:

// websocket and http servers
var webSocketServer = require(\'websocket\').server;

...
...
v         


        
5条回答
  •  醉梦人生
    2020-11-29 16:25

    interesting post (similar to what I am doing). We are making an API (in C#) to connect dispensers with WebSockets, for each dispenser we create a ConcurrentDictionary that stores the WebSocket and the DispenserId making it easy for each Dispenser to create a WebSocket and use it afterwards without thread problems (invoking specific functions on the WebSocket like GetSettings or RequestTicket). The difference for you example is the use of ConcurrentDictionary instead of an array to isolate each element (never attempted to do such in javascript). Best regards,

提交回复
热议问题