I searched a lot, but unable to find the answer.
Mukesh Negi wrote:If while writing to the socket's output stream, the peer closes the connection (or because of some reason the connectivity is loosed), will my program wait infinitely or will it timeout after certain amount of time.
I searched a lot, but unable to find the answer.
Henry Wong wrote:Well, with TCP, if the peer closes the connection, it *should* be propagated back to the other side
Mukesh Negi wrote:
According to my understanding SO_TIMEOUT is considered only when we are reading from the socket, I have tried this and it worked. The time_out parameter that we give in socket.connect method is the time_out only when establishing the connection.
I am more concern about when writing to the socket. I have read some where that write does not blocks but read does blocks.
My understanding on socket.write is following, please correct me if wrong:
When writing to socket it completely depends on the TCP buffer, I mean, if we are writing a small amount of data, then it will immediately wait on socket.read to read the acknowledgement and here SO_TIMEOUT will come into picture. This is so because we have completely written data to the buffer and hence our write operation is completed. But this is not the case with large data as our write operation does not get completed.
Henry Wong wrote:
Oops... my mistake. I meant the SO_KEEPALIVE socket option. Using this option, on a TCP socket, *should* enable checking at the switches for packets (or KA packets), and reset the socket when they timeout.
Regardless, as already mentioned, with the large mix of hardware (and network hops), this feature is not guaranteed to work in all cases. And if you want that guarantee, you will have to implement it into your protocol.
Sorry for the confusion,
Henry
Mukesh Negi wrote:
Henry really thanks for your reply. Above, you have mentioned about SO_KEEPALIVE option, which is used to keep connection alive.
Henry, but I don't want to keep it alive. I want to break the write operation after specified time. The second thing you mentioned is about hardware, again same thing implies here as well. I just want to break the write after specified time.
Mukesh Negi wrote:
Actually, I am using org.apache.commons.net.ftp api to deal with file uploading and downloading. And I am looking for the solution while uploading the file.