Reputation: 846
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.
Upvotes: 2
Views: 2824
Reputation: 43688
On Linux, you can see the kernel-maintained send-queue and timeouts by running:
netstat -tanpo
When the connections terminates abruptly, due to an error or a timeout, the client can notice by checking the return values from write()
, shutdown()
and close()
.
Upvotes: 1
Reputation: 51137
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 /proc
as well as measured network parameters.
edit: An app can check the size of the outstanding send queue by using the SIOCOUTQ
ioctl; 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.
Upvotes: 8
Reputation: 29011
Yes. Depending on the configuration, it even may wait some time to see if it can recover the connection. Even, tcp timeouts can be of minutes... Note here for example, the parameter tcp_fin_timeout
and other parameters related to timeouts.
Upvotes: 2