Dmitry
Dmitry

Reputation: 2158

Continuously write to TCP socket without reading

I have a TCP client server application written on boost 1.53. Based on the client command I have to start a server thread to write some data to a socket. But I have no guarantee that the client application would start reading from this socket. Is there any trouble writing data to a socket without reading from it? Won't be there any socket overflow or data corruption ?

Looking forward to hearing your ideas.

Thx, Dmitry

Upvotes: 0

Views: 2053

Answers (2)

Joni
Joni

Reputation: 111259

What happens when sending data to a slow or non-cooperative remote side is covered by the flow control aspect of TCP.

Suppose you try to send data and the application in the remote side refuses to read it. Eventually the remote side's receive window becomes full, and it will indicate this by sending an ACK with a window size 0. Your network stack stops trying send new packets until an ACK with a larger window size is received. If you keep trying to send data it accumulates in the send buffer in your network stack. When the buffer becomes full writing to your side of the socket blocks.

Upvotes: 3

Jeremy Friesner
Jeremy Friesner

Reputation: 73081

Using TCP, that won't be a problem. The server will detect that the client isn't reading, and hold off on sending more data until the client has acknowledged receipt of the already-sent data. In this case the server thread will block until the client is ready to accept more data.

Also TCP packets are checksummed, so if any get corrupted in transit the client will reject them and the server will resend them.

Upvotes: 0

Related Questions