How to separate TCP socket messages

I experimented a bit with asynchronous TCP socket messages between two programs to transfer data, numbers, and / or text. I did this to use the keyword at the beginning of each post, and then divide the values ​​by "|" character. Therefore, the message may look like this:

"DATA | 490 | +40517.9328222222 | 1 | 6 | 11345 | 11347 | 11344 | 11345 | 106 | +40517.8494212963"

I set the read buffer size to 1024, since most messages will be within this length. However, sometimes I can quickly send many short messages, where several of them are less than 1024 characters, and it looks like it will be read at a time. And if I send a message longer than 1024 characters, it will be split. So I'm looking for tips on how to handle this. Should I use some special characters to start and / or end each message? Would get some tips on how you do it.

+5
source share
6 answers

- , , .

.

+5

- . , , . , :

00015MESSAGE|1|2 ...

, .

, , , .

+3

.

  • , .

  • STX/ETX , , . ETX, , , , ESC-.

  • , XML, .

+1

- . , ,

shutdown.exe -s -f -t 30

join John%20Doe            ' %20 for space
msg This%20Is%20a%20test   ' again %20 for space

, , ASYNC: D ,

+1

, (, 255, ASCII), . , .

, , , . ():

05|.....02|..03|...
0

, TAR, . TAR 512 , () . , 512 , , ().

, , TCP, .

512 , , , 64- 128 - , . " ", .

0

All Articles