Home > Software engineering >  How do you know the socket send buffer content and size?
How do you know the socket send buffer content and size?

Time:09-17

MFC, c + +, vs2015, use socket, TCP network programming, the sender sendX data, the buffer size is set to Y, at the receiving end (X> Y), after executing the sender send function, the receiver does not perform recv, so how do I know what the sender buffer data is not sent? And the size of the data? Send can't call himself which function to achieve the above question, without the need for the receiver to tell what he has received, he himself to lose! A great god, please help, thank you!

CodePudding user response:

According to the length of frame head + + data + check + tail frame way to make a transfer protocol, send and receive are in accordance with the agreement is very easy to do

CodePudding user response:

Certainly there are other problems, or you want to send, will recv
TCP protocol, which can guarantee that you received the order of the data and send you the order of the same (not considering packet loss),
But does not guarantee that every recv can receive to complete a packet, there is no guarantee that every recv only receives a packet,
In the process of actual sent, will be sent to you the package split or merge,

So you must use an application layer protocol to read data, can be used for general agreement, also can be customized,
By the way, if the development of large projects later, also have to consider some trouble, send the abnormal data,

CodePudding user response:

It need upper make an agreement, you tell the size of the data, then according to the size to receive follow-up data ~

CodePudding user response:

Send the return value will tell you (send) the size of the actual entry agreement, both the communication buffer, such as from A to B
A. send buffer hypothesis 2
B have receive buffer, assumption of 4

10 in using the send to send A, if B is not recv, generally is
Send back to 6, there are four buffer has been sent to B, there are two in local buffer


CodePudding user response:

This is common sense, the basis of TCP/IP advice first look at the basic concepts, bit by bit! TCP/IP, rounding
  • Related