# How to use websockets to send a reply back to client

**URL:** https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448
**Category:** General
**Created:** [29 October 2023 18:14 UTC](https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448 "2023-10-29T18:14:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [29 October 2023 18:14 UTC](https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448/1 "2023-10-29T18:14:58Z")

</div>

So in my fun MQTT project I thought - lets try seeing if I can set it up to use websockets (just on LAN)

So, I created this little flow

```auto
[{"id":"99a9e9a5e664458a","type":"websocket out","z":"f7546f055375d300","name":"","server":"5ffaa82e38835477","client":"","x":1150,"y":600,"wires":[]},{"id":"c9a58f87db1d1413","type":"change","z":"f7546f055375d300","name":"set CONNACK","rules":[{"t":"set","p":"payload","pt":"msg","to":"[\"0b00100000\",2,0,0]","tot":"bin"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":560,"wires":[["f9ae1ff880e022d1","99a9e9a5e664458a"]]},{"id":"3f40582d7a5603c2","type":"switch","z":"f7546f055375d300","name":"Test packet type","property":"payload.0","propertyType":"msg","rules":[{"t":"eq","v":"16","vt":"num"},{"t":"eq","v":"0xC0","vt":"num"},{"t":"gte","v":"0b00110000","vt":"num"},{"t":"eq","v":"0x82","vt":"num"},{"t":"eq","v":"0b10100010","vt":"num"},{"t":"eq","v":"0b11100000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":7,"x":675,"y":580,"wires":[["c9a58f87db1d1413"],[],[],[],[],[],[]],"l":false},{"id":"f9ae1ff880e022d1","type":"debug","z":"f7546f055375d300","name":"Test","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"msg","x":970,"y":640,"wires":[]},{"id":"2251a27865d0e996","type":"join","z":"f7546f055375d300","name":"","mode":"custom","build":"buffer","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"bin","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":600,"wires":[["3f40582d7a5603c2","4ac41d3fa7382b13"]]},{"id":"4ac41d3fa7382b13","type":"junction","z":"f7546f055375d300","x":660,"y":640,"wires":[["f9ae1ff880e022d1"]]},{"id":"76eb165d46f3715b","type":"websocket in","z":"f7546f055375d300","name":"","server":"5ffaa82e38835477","client":"","x":440,"y":600,"wires":[["2251a27865d0e996"]]},{"id":"5ffaa82e38835477","type":"websocket-listener","path":"/ws/example","wholemsg":"true"}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/2/4285b7f2848d6e5c01c74bc4f3a74748390fed9b.png)

And it receives a connection message (but in two parts - hence need for join) and using my same switch that I used for TCP connections - I check the packet and then send an acknowledgement

But my client doesn't actually connect so I wondering if I've setup the websocket out node properly  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c6a4f9fd2c5669ab489a6aaf4aee492383a58ad.png)

The TCP out node has a reply mode but the websocket one seems to lack this

[edit] note - it may be an issue with my client but I just need to know whether I#ve setup NR correctly

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [30 October 2023 09:44 UTC](https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448/2 "2023-10-30T09:44:24Z")

</div>

I think I've got my answer - the out node show automagically send the response back to the connecting client

Will need to diagnose further why the CONNACK msg doesn't seem to being received

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c390213219d60ef38cd640ab0f18f13613b7a812.png)

---

<div class="post-metadata">

### Author: ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)
#### Post date: [30 October 2023 10:26 UTC](https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448/3 "2023-10-30T10:26:32Z")

</div>

It was my fault - for some reason I'd selected entire message

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/86fd1bd43de14b36c19083b5de729e1d40e304f1.png)

Now works fine 🙂

---

<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: [29 December 2023 10:26 UTC](https://discourse.nodered.org/t/how-to-use-websockets-to-send-a-reply-back-to-client/82448/4 "2023-12-29T10:26:38Z")

</div>

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