# How does the TCP In node receiving buffer payloads split it into messages?

**URL:** <https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213>\
**Category:** General\
**Created:** [12 February 2022 11:23 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213 "2022-02-12T11:23:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flipzz](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@flipzz](https://discourse.nodered.org/u/flipzz)\
**Post date:** [12 February 2022 11:23 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/1 "2022-02-12T11:23:46Z")

</div>

Hi,

I am using the TCP In node to listen to a port where a legacy application is sending a stream of binaries that I am decoding using buffer parser. So far so good.

I have one problem though: How does the TCP In node know when it split up the stream into multiple different messages? The stream I am handling from the legacy app is rather old-school but it seems like TCP In is sometime creating multiple messages for the "same legacy message" if you understand what I mean. Is it any way to steer how the input stream seperates into messages or how does TCP do that in general?

Kind regards

---

<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:** [12 February 2022 13:37 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/2 "2022-02-12T13:37:55Z")

</div>

Is this using the TCP-in node or the TCP-request node ?  
The TCP node just passes on what it is handed by the underlying OS - It may or may not decide to split a buffer or not.

---

<div class="post-metadata">

**Author:** ![flipzz](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@flipzz](https://discourse.nodered.org/u/flipzz)\
**Post date:** [12 February 2022 13:45 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/3 "2022-02-12T13:45:01Z")

</div>

I am using the TCP-In node with a stream of buffers setting. When I route it to the debug it seems to split the buffer a bit random.

I think that I probably need to pre-process the buffer with buffer parser so the buffer gets chopped up in segments according to the length I get as the first part of the buffer?

---

<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:** [12 February 2022 13:48 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/4 "2022-02-12T13:48:06Z")

</div>

It depends if you need the rest of the buffer later. Ideally you feed into a function node and have some code in there to add each incoming buffer to any previous leftovers (held in node context) ... then slice off the front part you need and send that on... keeping the remainder for the next part to arrive.

---

<div class="post-metadata">

**Author:** ![flipzz](https://avatars.discourse-cdn.com/v4/letter/f/bb73d2/32.png) [@flipzz](https://discourse.nodered.org/u/flipzz)\
**Post date:** [13 February 2022 10:03 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/5 "2022-02-13T10:03:36Z")

</div>

Thanks, you don't happen to have a small example of this?

I've tried using some examples I found and it seems to work rather alright if the data comes in one stream in the TCP In but if it "splits up" in the debug I get problems. My example flow looks like this (also attach the json).

 ![Screenshot 2022-02-13 at 11.01.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/838b4024ded6906cd0dbd2200d9bd198e55458c7.png)

Do you mean that I should add a function node just after the TCP IN to handle the buffer?

[flows.json](https://discourse.nodered.org/uploads/short-url/iwQM7rvFA1f4HxKPkM1A6PGEPmt.json) (7.3 KB)

---

<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:** [14 April 2022 10:03 UTC](https://discourse.nodered.org/t/how-does-the-tcp-in-node-receiving-buffer-payloads-split-it-into-messages/58213/6 "2022-04-14T10:03:47Z")

</div>

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