Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

writing data to a socket that is sent in 2 frames

Tags:

c

linux

tcp

sockets

My appliactions sends through the wire using socket small messages. Each message is around 200 bytes of data. I would like to see my data sent in 2 frames instead of 1. My questions are

  1. How to do that i.e. is there a way to cause TCP to automatically split the buffer in 2 frames?
  2. Do I get the same if I send my buffer in 2 separate writes?

I am using Linux and C.

like image 611
Abruzzo Forte e Gentile Avatar asked May 08 '26 15:05

Abruzzo Forte e Gentile


1 Answers

How to do that i.e. is there a way to cause TCP to automatically split the buffer in 2 frames?

TCP is a stream communication protocol, all data is continuous. You should split your data by delimiters.

For example, in HTTP protocol each separated request is splited by two \n.

Do I get the same if I send my buffer in 2 separate writes?

No, you will receive them as a one continuous data stream. Frames are meaningless.

Note: Before you receive any data TCP in your application, packets are separated but OS collect and reassemble them. This process is transparent from your application.

like image 152
masoud Avatar answered May 11 '26 05:05

masoud