Establishing a connection between two computers using TCP nodes.

1,057 views
Skip to first unread message

Sindhuri Bhattaram

unread,
Oct 13, 2015, 4:45:13 PM10/13/15
to Node-RED
Hello all... My knowledge with node-red and anything related to programming or internet-comp-things is very very minimal. So kindly bare with my silliest doubts possible.

I want to establish a connection between two computers and exchange information in the form of strings. So basically both my computers have node-red servers running on them. What parameters should I set in the TCP nodes? How will I know which port number to use? The locolhost means the IP address of the computer that the program is running on> which means I can get my IP by using ipconfig from cmd?

Where should I use a TCP in and TCP out node? I have many more questions to ask which I can formulate once I get started with these first!

Really thanks for bearing with my silly queries! But I really have no clue about these!

Sindhu

Mauro Defendi

unread,
Oct 13, 2015, 5:57:31 PM10/13/15
to Node-RED
Hi Sindhu,

try 'websocket'. In node-red 'websocket node' both in/out.

Google it and you will find tons example.

Mauro

Dave C-J

unread,
Oct 13, 2015, 6:14:37 PM10/13/15
to node...@googlegroups.com
Hi Sindhu,

As usual it depends which end you consider to be the client an which the server - for no particular reason we chose the sender to be a client and the receiver to be a server - but these can be changed in the node options.

Set the TCP in node to  "Listen on"... the port can be whatever you want - typically above 1024. (and below 65536) - as long as it is not in use by anything else... most common services are below 1024 so a random choice should be OK - (apart from 1880 - which Node-RED uses of course !!!)

Then at the sending end - you would use a TCP out node set to "connect to" - set the same port as you used above and set the Host to be the ip address of the other machine - and if you are just sending strings - set it to output Strings.

Here is a simple example running on one machine  - you would need to run half on each machine and change the 127.0.0.1 to the IP of the other machine.... good lluck

[{"id":"646d684.f9b9298","type":"tcp in","z":"9e538f88.61ac7","name":"","server":"server","host":"","port":"5555","datamode":"stream","datatype":"utf8","newline":"","topic":"","base64":false,"x":283,"y":986,"wires":[["7e59ee9f.81a61"]]},{"id":"f3b49215.0c4b7","type":"tcp out","z":"9e538f88.61ac7","host":"127.0.0.1","port":"5555","beserver":"client","base64":false,"end":false,"name":"","x":212,"y":941,"wires":[]},{"id":"f111339f.0eeed","type":"inject","z":"9e538f88.61ac7","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":111,"y":890,"wires":[["f3b49215.0c4b7"]]},{"id":"7e59ee9f.81a61","type":"debug","z":"9e538f88.61ac7","name":"","active":true,"console":"false","complete":"false","x":483,"y":953,"wires":[]}]

Julian Knight

unread,
Oct 14, 2015, 4:04:20 PM10/14/15
to Node-RED
As always with these things, you have lots of choice!

A direct TCP connection might be OK but doesn't have much in the way of resilience. As Mauro say's websocket connections also work just fine. But if you want better control and resilience of the link, you might want to look at using MQTT instead. Although this needs a broker, it is easy to set up and uses little resource but gives you a lot.


On Tuesday, 13 October 2015 23:14:37 UTC+1, Dave C-J wrote:
Hi Sindhu,

As usual it depends which end you consider to be the client an which the server - for no particular reason we chose the sender to be a client and the receiver to be a server - but these can be changed in the node options.

...

Sindhu

unread,
Oct 14, 2015, 8:25:56 PM10/14/15
to Node-RED
Hello Dave,

I created a flow on both ends similar to what you said earlier. Where should I look for the messaged that is transmitted? My sender side flow displays "connected" and my receiver side displays "2 connections" below the tcp in node. I hope they are actually connected an hope to see the messages somewhere!

Dave C-J

unread,
Oct 15, 2015, 3:36:01 AM10/15/15
to node...@googlegroups.com
all debug nodes should output their messages into the debug tab window to the right of the screen.
Inline images 1
Reply all
Reply to author
Forward
0 new messages