Is there a way to configure the timeout in which a socket expects to receive an ACK for sent data before it decides that the connection has failed?
I'm aware this can be done at the application level as well, but since every packet I send is ACK'd anyway, and I just want to know if my data is received, using additional data at the application level to accomplish the same thing seems wasteful. (Not to mention, my particular application uses per-byte charged cellular links.)
Note: As per my previous question --
What conditions cause NetworkStream.Write to block? -- you cannot rely on .Write
throwing an exception in order to determine that data is not being sent properly.
Answer: Just set the SO_TIMEOUT on your Java Socket, as shown in the following sample code: String serverName = "localhost"; int port = 8080; // set the socket SO timeout to 10 seconds Socket socket = openSocket(serverName, port); socket. setSoTimeout(10*1000);
Definitions. ACK Timeout = Air Propagation Time (max) + SIFS + Time to transmit 14 byte ACK frame [14 * 8 / bitrate in Mbps] + Air Propagation Time (max)
To disable Delayed ACKs, use the TCP_QUICKACK socket option. Enabling the TCP_NODELAY option turns Nagle's algorithm off.
socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.
There is mention of a "user timeout" in some IETF RFCs (5482 793) which does what is being asked for.
Some other operating systems support this as a socket option but not Windows unfortunately.
Without this option, the only ways to reduce the time until abort in this scenario would be to reduce the number of retransmission attempts, or reduce the initial RTT.
On Windows the former can be controlled (machine wide..) via netsh/registry: Tcp Max Data Retransmissions.
Is it feasible to just abandon the current connection via your own timeout, and make another if required?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With