Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flush the TCP receive data buffer?

I am doing a program with Winsock to create a client and send data to a server in response to which server replies with a specific data block received, this is continued a number of times.

The problem is some times my data block 1 gets overlapped with data block 2 so I want to flush out my TCP reception buffer after the 1st complete reception.

I reffered to this link also How do I "flush" a TCP Client Buffer? but I cant wait till the reception occurs

How can I flush the TCP receive data buffer? I am doing my project in visual c++

like image 994
user3395801 Avatar asked Jun 04 '26 15:06

user3395801


1 Answers

The only way to "flush" the receive buffer is to read from it. After the first read, keep reading from the socket, throwing that data away, until there is no more data available to read. Use select() with a timeout to detect when the socket is still receiving data.

If data is being "overlapped" then either the server is not sending the data correctly on its end (overlapping send() calls), or you are not reading the data correctly on your end.

like image 123
Remy Lebeau Avatar answered Jun 07 '26 06:06

Remy Lebeau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!