TCP node what is buffer and stream exactly?

I was experimenting with an Arduino to Node-RED, where I heavily tested the TCP connection to be slow. Here I got a bit confused what the TCP node exactly does. The documentation couldn't help me further. I made a list how I think the TCP node works, I hope somebody can confirm of correct me. That would be very appreciated.

It is for the nodes TCP in and TCP request. As well as the UDP variants.

Output:
Stream of: This means that the node expect an unknown and for unknown amount of time.

  • Buffer? Is this the data that fits in the memory of my Ethernet card or OS level?
  • String: Stream of characters. Delimited by character(s) of choice.
  • Base64. Delimited with LF command.

single: this is a complete message?

  • Buffer? Is this the data that fits in the memory of my Ethernet card or OS level?
  • For string? Is there a end character in Javascript like \0?
  • Base64. Delimited with LF command.

Each option will send data when connection is closed from the sending device.

nodejs variables are of different types such as number, boolean, string and buffer... So in this case the code is just returning the either the raw bytes that arrive - usually it looks like an array of hexadecimal numbers eg ["0x48","0x65","0x6c","0x6c","0x6f"] - or it converts it and returns a string eg "Hello".

And yes - stream means it is expecting more and to keep waiting - single will return whatever it receives as it gets itl

Thanks for the quick answer.
But what is defined as a buffer? Is that a certain length, data received in a time window, ... ?
When I tested the buffer with a non-continouse communication from an Arduino it seems to be random in behavior. Sending abc, delay of 5s followed with def\r\n It sometimes returns abc, or abcdef\r\n.
I wrote the memory of the Ethernet card, but that makes no sense for Javascript. Javascript acquires the data from the operating system.

How does the node recognizes a complete String message? And is my assumption about the LF correct? Or is there in Javascript someting like the \0 like C?

it's whatever the underlying OS delivers... it may be your complete message or it may not. Usually it is up to something like 16k bytes - but it really does depend on the operating system and how it handles tcp latency and buffering and timeouts.

Complete string message - again generally it is just the end of the buffer being sent - but if you set a delimiter then it will only send on the parts when it sees that delimiter... - eg if you set it to split a stream on \n then send in Hello\nWorld then first time you will get Hello then next time you send Hello\nWorld you will get WorldHello as the World was held from the last time then Hello arrived then the split character ... etc

1 Like

Thanks. That explains a lot.

I use already for communication with the Arduino the Stream of Strings with a delimeter. No happy flow proof. It is just I wanted to know what the other options really did. And I now know them thanks with your help.