WebSocket Node multiple clients

Hello,
if 2 clients are connected to same webscoket node, is there a way send a message to specific client instead of broadcasting the message to all connected clients?

in another way I have 2 or more clients connected through websoket and i need to handle each communication channels independently without creating a Websocket node for each client.

and is there a way to manipulate the websocket URL programmatically through a message?

Yes, when you see data coming back from the client, you will see that the msg contains an websocket client ID. Just note that reloading the client page will force that ID to change so it isn't terribly reliable. But you can take that and use it when sending a websocket out msg and it will only go to that client.

I don't believe so.

Dashboard (rather than the websocket nodes) uses a subset of the full Socket.IO features but even that doesn't implement things like "rooms".

uibuilder gives you more control but still doesn't allow fine-grained control of the websockets. It does, however, implement a different Socket.IO channel for each uibuilder node (Dashboard has only a single connection). Implementation of features such as rooms has long been something that I've wanted to implement but there have been too many competing requirements to implement first.

Hello Thanks or your reply
seems I'm missing something here, so what is the clientID property in node red. my message is being send to all connected clients connected to the Websocket endpoints
I can't specify which client receives the message

Hi @wahibmichael

From the sidebar help of the WebSocket Out node:

If you want to broadcast a message that started at a WebSocket In node, you should delete the msg._session property within the flow.

So, the property you are interested in is the msg._session property.

Have a look at that property with a Debug node for a message that has arrived from a WebSocket In node.

1 Like

Thanks @knolleary for your usual support :slight_smile: it's always a good idea to read the node help section

just to validate my idea. I have an (MQTT in) node connected to a (websocket out) node, if i want to send the Mqtt message to specific websocket client I have to set msg._session to the connect client sessionID and only this client will receive the message.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.