Home > Back-end >  About TCP Socket glue bag and subcontract processing method and some discussion of knowledge
About TCP Socket glue bag and subcontract processing method and some discussion of knowledge

Time:09-27

Today in the group asked a question:
"CP Socket glue bag and the processing of the subcontract the maturity of C/C + + library is?
You usually is how to deal with, your message structure is the frame head length + + CRC or frame head + + CRC + frame length tail?
And then parse the data the unpacking of the subcontract library or code? Best is a mature libraries or write their own in the project has been the long-term use of authentication code, can share the following?"

Message is found that many people design, without the frame head length + data directly, the loss of data or data, TCP cannot jump, directly read the length of the front, and then according to the length of the read data,


Here is our conversations, he said, right? Your message is how design?
The
reference

[diving] demon elder brother and introverted disciple of the master (2430) 14:59:06
I tend to be
"Length + data content
"
[loud gurgling (26739) 15:00:23
Demon elder brother and introverted disciple of the master
I tend to be
"Length + data content
"Frame head + + CRC + frame length tail @ demon elder brother and master apprentice, I feel so safe some introversion

[loud gurgling (26009) 15:00:50
In the condition of the damaged frame head can be tested and discarded

[diving] demon elder brother and introverted disciple of the master (3780) 15:01:00
Head and tail, feeling the excess

[diving] demon elder brother and introverted disciple of the master (280) 15:01:17
Length + data (the data, can be any data)

[diving] demon elder brother and introverted disciple of the master (780) 15:01:33
TCP is a reliable protocol, damage?

[diving] demon elder brother and introverted disciple of the master (370) 15:01:54
The HTTP protocol is also not so design

[diving] demon elder brother and introverted disciple of the master (20) 15:05:33

For example, are widely used in the HTTP protocol, based on the TCP,

HTTP header (include the Content - Length), and then later is data
A plenty of chunked, is behind the length + data
[diving] demon elder brother and introverted disciple of the master (20) 15:09:31
+ data length, the length, is boundary

[loud gurgling (29) 15:10:35
Demon elder brother and introverted disciple of the master
+ data length, the length, is boundary
@ demon elder brother and introverted apprentice, you have to find the length of the master, just behind the frame head, that is, to find the frame head

[diving] demon elder brother and introverted disciple of the master (0) 15:10:41
You don't need

[loud gurgling (269) 15:10:55
Demon elder brother and introverted disciple of the master
Depressed
@ demon elder brother and introverted master apprentice, then how do you find the length of the

[diving] demon elder brother and introverted disciple of the master (2) 15:11:02
Length, has set a boundary

[loud gurgling (26) 15:11:07
The first frame length is in front of a few bytes?

[diving] demon elder brother and introverted disciple of the master (20) 15:11:21
If you start to send, is in front of length!

[diving] demon elder brother and introverted disciple of the master (20) 15:11:39
TCP is streaming

[loud gurgling (29) 15:11:39
Are you sure the first frame in front of a few bytes without losing 100%, not mutations, not been tampered with

[diving] demon elder brother and introverted disciple of the master (20) 15:11:54
Loud gurgling
Are you sure the first frame in front of a few bytes without losing 100%, not mutations, not been tampered with
,,, let's talk about it, you look at what is called the TCP

[diving] demon elder brother and introverted disciple of the master (20) 15:12:13
Loud gurgling
Are you sure the first frame in front of a few bytes without losing 100%, not mutations, not been tampered with
For this to work, so what you add frame head, would be futile

[diving] demon elder brother and introverted disciple of the master (20) 15:27:48
TCP development of 40-50 years (because I have my own writing protocol stack, the more attention, some time ago watching video introduction, a fright)

[diving] demon elder brother and introverted disciple of the master (20) 15:28:55

Be afraid of the length + check + data, in fact, the TCP layer have a check,
[diving] demon elder brother and introverted disciple of the master (280) 15:32:02
A connection-oriented, reliable, based on the byte stream -- -- -- -- -- what is "reliable"?

The underlying data, it is not reliable, there may be random sequence, packet loss, heavy bag... But TCP has finished processing,


CodePudding user response:

Baotou (length + other extensions version checking, etc.) + inclusions (data)

CodePudding user response:

reference 1st floor smwhotjay response:
baotou (length + other extensions version checking, etc.) + inclusions (data)
yes, is there any other Suggestions? Or do you use frame structure can share out a hierarchy

CodePudding user response:

The length and content
Be almost enough functionality
Safety problem is bad is not about hacking
Just send the data error all don't know how to solve the
For example,
Originally prepared to send 10 "1234567890"
Not careful to forget to send the 10 send only the "1234579890"
"1234" to form a a large integer
Behind the code even if no more than fly
Will take following another message content as the contents of this message
Data dislocation GG

Note 10 received not because the network error
10 is the sender itself is not sent

CodePudding user response:

The simplest is the TLV, Type, Length and Value, on the premise of reliability is not very strict requirements, generally is enough,

CodePudding user response:

reference lin5161678 reply: 3/f
to oh!!!!! Is the net friend and I discuss, they always said the TCP have check, error is very low, calibration is not necessary to refute but I them you this reason is good

CodePudding user response:

references on 4th floor cool west wing response:
the TLV, is the most simple Type, Length and Value, on the premise of reliability is not very strict requirements, generally is enough,
what is the Type? Is the Value calibration Value?

CodePudding user response:

refer to 6th floor bandaoyu response:
Quote: reference on 4th floor cool west wing response:

The simplest is the TLV, Type, Length and Value, on the premise of reliability is not very strict requirements, generally is enough,
what is the Type? Is the Value calibration Value?
Type is the Type of data transmission, to the end to this Type can be according to the corresponding Type of template to parse, the easiest Type can be defined as an enumeration

CodePudding user response:

references on 7th floor cool west wing response:
Type is defined as such: 1 json 2 protobuf 3...

CodePudding user response:

 
Typedef struct
{
Unsigned int total_packages;//the total number of packages
U_long index;//the current package serial number
Int total_len;//
the total length of the dataChar data [ONE_PACKAGE_LEN]; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related