Hi There,
I'm confused about a setup of nodes:
I have two tcp-in nodes one is listening on port 1234 (localhost) (the listener) and the other (the bottom one) is connected to port 1234 on localhost (the connector), i.e., the "connector" is connected to the "listener".
The change node sets the payload to 'ok' and passes that on to the tcp-out node in reply mode.
What I don't understand is the relationship between the two tcp-in nodes.
What happens when I trigger the inject button sending a payload of "hello world"? The debug 430 node joined to the "listener" receives "hello world", the debug 431 joined to the "connector" also receives "hello world".
So the tcp-out has connected to both and sent them both the message? Or has the "connector" sent the message to the "listener", having first received it from the tcp-out node? Or has the "listener", having received the message from the tcp-out node, sent the message to the "connector"?
Interestingly the "connector" (i.e. the bottom tcp-in node) also receives a second message with the "ok" payload from the change node. I.e., the "listener" sends message with a _session
attribute to the tcp-out node and that session - it seems - represents the "connector" node.
I had a look at the code for a tcp-out node in reply mode and it seems that if not session is set, then all connections are sent a message and when a session is set, then only the corresponding session is sent a message. So it seems that the tcp-out node sends all connections in the connection pool a message if there is no _session
attribute, i.e., the hello world message. The "ok" message is sent to the "connector" because .... the msg._session
points to it? Because the message originated with the "listener" node, how come the "ok" message ends up with the "connector" node?
Then I tested the setup with a telnet session to port 1234. When I sent messages via telnet, they all came out on the debug 430, i.e., on the "listener". This seems a little inconsistent since, for me, the telnet is a type of tcp-out node so its message (from the telnet) should, I would have thought, gone to both tcp-in nodes. The "ok" messages generated by the tcp-out node only went to the telnet session, i.e., came back to telnet, it was not sent to the "connector" node. In fact the connector node received no messages when I use telnet.
Final question, is this setup an incorrect setup and something that should not be done? I mean I didn't have a use case, I just randomly put some tcp nodes together.
[{"id":"cdf9310b209c1838","type":"tcp in","z":"61cea49a1b24d505","name":"","server":"server","host":"","port":"1234","datamode":"stream","datatype":"utf8","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":611,"y":567,"wires":[["922894e195cfced3","be8b10d81cf90c24"]]},{"id":"efcdb65d343c28d5","type":"tcp out","z":"61cea49a1b24d505","name":"","host":"","port":"","beserver":"reply","base64":false,"end":false,"tls":"","x":1000,"y":441.5,"wires":[]},{"id":"b19e4f202ce8e9f9","type":"inject","z":"61cea49a1b24d505","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"hello world","payloadType":"str","x":611,"y":444.5,"wires":[["efcdb65d343c28d5"]]},{"id":"922894e195cfced3","type":"change","z":"61cea49a1b24d505","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":812,"y":502.5,"wires":[["efcdb65d343c28d5"]]},{"id":"dd0e889f20803d72","type":"tcp in","z":"61cea49a1b24d505","name":"","server":"client","host":"localhost","port":"1234","datamode":"stream","datatype":"utf8","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":618,"y":711.5,"wires":[["0cad58dfd4a0f54e"]]},{"id":"be8b10d81cf90c24","type":"debug","z":"61cea49a1b24d505","name":"debug 430","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":859,"y":622,"wires":[]},{"id":"0cad58dfd4a0f54e","type":"debug","z":"61cea49a1b24d505","name":"debug 431","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":877,"y":842,"wires":[]}]
EDIT: ok, I think I understand it: the "connector" receives the hello world message from the tcp-out node. It sends it to the "listener", that then it sends back an "ok" to the "connector". But in fact that only works if the "connector" has its ouput set to "stream of strings", setting it to "single string" ensures that it procedures no output at all. (I'm not using delimiters with my strings.) Yet the listener then also receives the hello world message ... from the tcp-out node probably.