I am developing a real-time Android application and have an issue with detecting errors on an ObjectOutputStream
which is connected to a TCP
network Socket
. I am calling writeObject
followed by a flush
on the stream as normal, however when the receiving node unexpectedly dies I need to know about it right away (within seconds). Unfortunately when the node goes down开发者_如何学运维 the server's call to writeObject
and flush
do not throw IOException
s and instead succeed.
I am assuming there is internal buffering that takes place with these calls and that is the reason for its success? Is there any way to know when a node is down via writeObject
or other means after a Socket
has been successfully created?
It is worth noting that the TCP Socket
s are left open for performance reasons, so setting a timeout on connect
for every writeObject
is not possible.
when the receiving node unexpectedly dies I need to know about it right away (within seconds)
You can't. TCP doesn't tell you. It doesn't know. It is busy doing buffering and retrying. It will wventually time out, and if you do a write after that you will get the exception. There is no control whatsoever over how long that takes.
精彩评论