Is confirmation of the response necessary when using send () / recv () Winsock?

Using Winsock, C ++, I send and receive data using send () / recv () , a TCP connection. I want to be sure that the data has been delivered to the other party, and to ask myself whether to send any confirmation message after (if) receiving the data using recv .

Here are two options and, please, advice on where to go:

  • If send returns the size of the passed buffer, suppose that the data was delivered at least to recv on the other side of the wire. When I say “at least”, I mean, even if recv is not working (for example, due to insufficient buffer, etc.), I do not care, I just want to be sure that I did my part of the work It worked correctly - I completely sent the data (i.e. the data reached another machine).

  • Use additional confirmation: after receiving data from recv, send back some identifier of the received packet (part of the header of each sent message), signaling the successful operation of receiving this packet. If after some interval I do not receive such a "confirmation message", return the rejection code from the sender function.

The second answer looks more secure, but I do not want to complicate the transfer protocol if it is redundant. Also note that I'm talking about a TCP connection (which is more secure in itself than UDP).

Are there any other mechanisms (maybe some other APIs? Maybe WSARecv () / WSASend () work differently?) To ensure that data is delivered to the recv function on the other hand?

If you recommend the second method, could you give me a piece of code that allows me to use recv with a timeout to get confirmation? recv is a blocking operation, so it will hang forever if the previous attempt to send failed (the other side was not notified). Is there an easy way to use recv with a timeout (without creating a separate thread each time, which is likely to be redundant for each operation to send ).

, , ( ), - " "? , "" ? , , , !

EDIT: , , TCP/IP- (.. ), , MSDN: " > , . , ". , TCP , ( ) send() Winsock, . - TCP? - send() !

=============================================== =========

EDIT 2: , , , , TCP , - , send() Winsock ( , , ). , : send() Winsock , , ? , ( send()), send() , , ( , send()), ? , , send() "", send() , ? - TCP, Winsock API!

+3
4

TCP/IP, . , TCP UDP.

+3

: TCP, .

, : FAU_STG.4.1 , . (, - auditd(8) Linux , , .) , , , .

, , , TCP, - , , , .

TCP ( ); , , .

, ; , , - " ", - HTTP- SFTP.

, . . , send() . ( , - .) RST ICMP Unreachable, send() Reset Broken Pipe.

2

TCP, API Winsock.

. send() , TCP TCP.

TCP , . (. @Hans , .) peer , . (, , TCP out-of-band , , . OOB-, . .)

, TCP, . (, , , . , TLS TCP, , TLS .)

+3

UDP, , , ACK, UDP, TCP, ACKing .

+1

I think you complicate this too much, trust your TCP / IP program stack and the reliable delivery that it offers. TCP sockets work with data streams, not packets. Also, one call senddoes not guarantee one call recv.

0
source

All Articles