# TCP Duplex Communication

**URL:** https://discourse.nodered.org/t/tcp-duplex-communication/75634
**Category:** General
**Created:** [23 February 2023 13:20 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634 "2023-02-23T13:20:46Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 13:20 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/1 "2023-02-23T13:20:46Z")

</div>

I have search far and wide and every where i see people asking a similar question and the people answering the fail to understand the problem.

the problem!

I have an inject node that must write msg.payload="Hello World" when pressed.  
I have a debug node that display msg.payload.  
I have putty that can make a TCP connection to node red.

lets choose a TCP port 7000 for this example

please set up node red so that PUTTY can connect to TCP Port 7000

then Wire the inject node to the TCP connection so that when I press the Inject, the text appear in PUTTY over the TCP Connection Port 7000 AND wire the debug node to the TCP connection so that when I typed text in PUTTY it will appear in the debug node in node red

Can someone please show me how?

thanks

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 February 2023 13:51 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/2 "2023-02-23T13:51:26Z")

</div>

How much of that have you managed to get working?  
Export and paste here the flow showing what you have done so far.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [23 February 2023 13:58 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/3 "2023-02-23T13:58:51Z")

</div>

Further to that, do you mean that you want node-red to have a port open ready to receive an incoming TCP connection from a putty client, but you want node-red to send something before the remote client has made its first connection? I cannot see how that can be possible, the client has to make the connection first.

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 14:07 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/4 "2023-02-23T14:07:57Z")

</div>

Yes I want to run node red first. Then I want to start putty and tell putty to TCP connect to Port 7000  
on local host (127.0.0.1). So node red should be ready to accept the connection. (Putty and node red run on the same machine)

No node red does not / can not send something before putty has connected.

once putty made the connection i want to press the inject node and the text must appear in putty.  
then i want to type in putty and the debug node must display what i have typed.

Thanks

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 February 2023 14:42 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/5 "2023-02-23T14:42:15Z")

</div>

The TCP ports don't handle ssh - (which is by default what putty uses) - as there is a logon handshake that occurs... - If you use a raw TCP connection (eg nc or socat) then a simple back to back will do the basics

```auto
[{"id":"27fd830ddc02c1ee","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"d1df722b30636058","type":"tcp in","z":"27fd830ddc02c1ee","name":"","server":"server","host":"","port":"7777","datamode":"stream","datatype":"buffer","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":215,"y":240,"wires":[["4a8fd296423baf53"]]},{"id":"4a8fd296423baf53","type":"tcp out","z":"27fd830ddc02c1ee","name":"","host":"","port":"","beserver":"reply","base64":false,"end":false,"tls":"","x":490,"y":330,"wires":[]},{"id":"fc1f4b448e72c256","type":"inject","z":"27fd830ddc02c1ee","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello","payloadType":"str","x":235,"y":375,"wires":[["4a8fd296423baf53"]]}]

```

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

```auto
$ nc localhost 7777
Hello

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 February 2023 14:44 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/6 "2023-02-23T14:44:00Z")

</div>

I've not got putty to hand but maybe you can try this - raw mode -  
[Using PuTTY](https://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter3.html#:~:text=In%20order%20to%20make%20a,number%2C%20and%20make%20the%20connection).

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 14:52 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/7 "2023-02-23T14:52:12Z")

</div>

Yes PUTTY has a RAW mode not SSH. That is what I use.  
No Your TCP to TCP is not what I want. How do I send data from your tcp node back to your tcp:7777 node?

I have played with all the configurations of TCP in and TCP out and TCP response.

TCP is by design duplex, meaning I can send and receive data.

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 14:58 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/8 "2023-02-23T14:58:36Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 15:00 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/9 "2023-02-23T15:00:54Z")

</div>

This is step one of my problem. I can connect to the TCP Out node on Port 7000 and when I press the Hello World inject node I receive data on PUTTY

But when I type in PUTTY I get nothing Back

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 February 2023 15:04 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/10 "2023-02-23T15:04:01Z")

</div>

I'm not sure what you mean then... the in node is for data from your putty session. the hello is the inject you want to send back. You can intercept the data from the in node and do whatever you like with it ...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/ce11d13d74fffe1d9b52fd95fcc61c28987e61d3.png)  
but in my case I just echo'd it straight back...  
(the "out" node is set in reply-to mode)

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 15:11 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/11 "2023-02-23T15:11:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/af22b0898d2113654744b1b00ff15f7021cd6d53.png)  
Here is the closest I get to my solution.  
BUT I have to Run 2 PUTTY instances, I want to run 1. I want to send data to putty and then be able to reply with that same PUTTY instance

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [23 February 2023 15:41 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/12 "2023-02-23T15:41:07Z")

</div>

I think your issue is you are running putty on the same machine and the tcp in node would be listening on same port and ip as putty, try running putty on a differnt machine/ip.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [23 February 2023 16:15 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/13 "2023-02-23T16:15:30Z")

</div>

err - the OUT node MUST be set to reply to mode - so that the IN node is the one that binds and then the reply uses that same... works just fine (using nc) with the flow I posted originally (and indeed without the feedback wire)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/c/5ce4011884d93ac6d1bdbe301933b99460ab7800.png)

---

<div class="post-metadata">

### Author: ![Highlander](https://avatars.discourse-cdn.com/v4/letter/h/e9bcb4/32.png) [@Highlander](https://discourse.nodered.org/u/Highlander)
#### Post date: [23 February 2023 18:43 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/14 "2023-02-23T18:43:36Z")

</div>

Thanks!! it is working

I have been all over the settings

---

<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: [9 March 2023 18:44 UTC](https://discourse.nodered.org/t/tcp-duplex-communication/75634/15 "2023-03-09T18:44:02Z")

</div>

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