Home > Software engineering >  File when sending package sending and receiving package size is not consistent
File when sending package sending and receiving package size is not consistent

Time:10-09

Send (SOCKET s, const char FAR * buf, int len, int flags);
Recv (SOCKET s, char FAR * buf, int len, int flags);

Using TCP send and receive data, send the file is about 2 m, split into multiple packages to send, send 5 k at a time, at the receiving end, every time I need to determine the received packet size, so use
Int len=recv (s, buff, mMaxNub, int flags);
Found that every time I send the buff to 5 k, when receiving judge len every time there are 9 k, receives is bigger than the package was sent the package, this is how to return a responsibility?

CodePudding user response:

TCP is streaming protocol, cannot guarantee that every time is the last time to send the size of the receive

CodePudding user response:

reference 1st floor hurryboylqs response:
TCP is streaming protocol, can't guarantee every time receive is the size of the last time send

Yes, this know,
Problems from the first package, every time is significantly greater than the sender receive bag forwards the packet size, for the first time send 5 k should receive data to 10 k,

CodePudding user response:

refer to the second floor dianhui response:
Quote: refer to 1st floor hurryboylqs response:

TCP is streaming protocol, can't guarantee every time receive is the size of the last time send

Yes, this know,
Problems from the first package, every time is significantly greater than the sender receive bag forwards the packet size, for the first time send 5 k should receive data to 10 k,

The normal ah, you send all recv with circulating the send and circulation, to judge the send and recv return values

CodePudding user response:

Feeling is caused by glue bag, sticky mess the sender when sending package, all receive the out of joint,

CodePudding user response:

1, this is normal,
2, to ensure that the same size also is very simple, add a layer of receiving data processing, in accordance with the specified data length in baotou, assembled a length is not long not short package, and give the upper business processing;
3, stick pack this color force coin word this is trash, agreement is such a then a, stick a fart, would you say when you receive the data part you receive is caused by "unpacking"? This word is sb

CodePudding user response:

The custom of sending data format, such as baotou, length, data, and the end of the bag logo, then each receive judgment

CodePudding user response:

Can't play
1. Every time you send 5 k
2. Every time you receive will guarantee a 5 k, and receive, did you receive specified size is 5 k
3. The radical solution is to add a baotou, according to the baotou receive specified size

CodePudding user response:

Don't know how many predecessors in the TCP Socket
Send (many) send (less) send (wealth)
Has been so much illness recv (), recv (wealth)
Inside the trap!
http://bbs.csdn.net/topics/380167545
  • Related