# WebSocket Node multiple clients

**URL:** <https://discourse.nodered.org/t/websocket-node-multiple-clients/29917>\
**Category:** General\
**Created:** [11 July 2020 20:37 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917 "2020-07-11T20:37:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![wahibmichael](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wahibmichael/32/25578_2.png) [@wahibmichael](https://discourse.nodered.org/u/wahibmichael)\
**Post date:** [11 July 2020 20:37 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/1 "2020-07-11T20:37:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 July 2020 22:27 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/2 "2020-07-11T22:27:27Z")

</div>

> [@wahibmichael](#):
>
> 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?

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.

> [@wahibmichael](#):
>
> is there a way to manipulate the websocket URL programmatically through a message?

I don't believe so.

Dashboard (rather than the websocket nodes) uses a subset of the full [Socket.IO](http://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](http://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.

---

<div class="post-metadata">

**Author:** ![wahibmichael](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wahibmichael/32/25578_2.png) [@wahibmichael](https://discourse.nodered.org/u/wahibmichael)\
**Post date:** [11 July 2020 23:05 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/3 "2020-07-11T23:05:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 July 2020 23:11 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/4 "2020-07-11T23:11:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wahibmichael](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/wahibmichael/32/25578_2.png) [@wahibmichael](https://discourse.nodered.org/u/wahibmichael)\
**Post date:** [12 July 2020 00:03 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/5 "2020-07-12T00:03:44Z")

</div>

Thanks @knolleary for your usual support 🙂 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 September 2020 00:03 UTC](https://discourse.nodered.org/t/websocket-node-multiple-clients/29917/6 "2020-09-10T00:03:59Z")

</div>

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