# TCP/IP bi-directional messaging

**URL:** <https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732>\
**Category:** General\
**Created:** [24 July 2024 17:04 UTC](https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732 "2024-07-24T17:04:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kubasmyk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kubasmyk/32/38021_2.png) [@kubasmyk](https://discourse.nodered.org/u/kubasmyk)\
**Post date:** [24 July 2024 17:04 UTC](https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732/1 "2024-07-24T17:04:32Z")

</div>

Hi there, not sure I'musing correct words to describe exactly what I mean. Apologies.

Does node red support bidirectional messaging with existing nodes. (Without the request-response approach)?

I'm struggling to set it up. What I need is a code for

1)setting up the connection when a client outside connects to it  
2)sending to client  
3)receiving from client

What problems I have encountered in setting up Node red Windows Version 4.0 to talk to Labview using tcp/ip. Its older version of labview without mqtt.  
In my current workflow I can achieve the labview being a client and node-red being a server.  
labview is initiating the request and node red is replying. I can get data sent this approach both ways when client is initiating things. But would like to be able ideally asynchronously exchange data from either side. using tcp ip.

Could someone share the code, would be very grateful.

Kind Regards

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [24 July 2024 17:39 UTC](https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732/2 "2024-07-24T17:39:11Z")

</div>

Hi @kubasmyk

If I have this right, this is what you need to do...

Create 2 Nodes

- TCP IN (Set to `Listen On`)
- TCP OUT (BUT set it to `Reply to TCP`)

Connect a `Status` Node to `TCP IN` - why? because you can store the `_session` object representing the client's connection when they connect.

THEN

- Send to any client using `TCP OUT`  
appending `_session` to the `msg` object - you will need to engineer a state object to manage clients. omitting `_session` sends to all clients

when a client sends, and you need to respond, just ensure you include the correct `_session` in the outgoing `msg`

---

<div class="post-metadata">

**Author:** ![kubasmyk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kubasmyk/32/38021_2.png) [@kubasmyk](https://discourse.nodered.org/u/kubasmyk)\
**Post date:** [2 September 2024 15:08 UTC](https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732/3 "2024-09-02T15:08:37Z")

</div>

I have added the \_session id to the object before sending and it worked. Thank you

---

<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:** [16 September 2024 15:08 UTC](https://discourse.nodered.org/t/tcp-ip-bi-directional-messaging/89732/4 "2024-09-16T15:08:58Z")

</div>

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