Linux.
I have an ethernet cable between two computers. A simple server-client program in C to transfer a file from client to server. Client reads 100 bytes of data from the file and sends it to the server, and then waits for 2 seconds before sending the next packet.
When the client was sending the data, I pulled out the ethernet cable of the server side, I was expecting some error from the client since the connection is broke. But the client kept on writing the data to the pipe, and the server did not receive anything(but still it is waiting to receive).Client sent the whole file and stopped. Now, again I connect the ethernet cable, the server receives all the data sent by the client. How is this possible? Are the packets stored in some buffer and sent again when the connection is up?
Sorry for making it too long.
The whole point of TCP is to provide reliable data transfer despite having an unreliable network underneath. Basically, the way it works is TCP only considers data sent after it receives an acknowledgement packet from the remote machine; until then, the kernel stores the data locally. The amount of time it’ll be buffered for can be quite long, depending on a bunch of settings in
/procas well as measured network parameters.edit: An app can check the size of the outstanding send queue by using the
SIOCOUTQioctl; see the tcp(7) manpage. The same manpage discusses error handling as well.If you want that data to be lost instead of buffered, use UDP.