开发者

ObjectOutputStream IOException / timeout on Android

开发者 https://www.devze.com 2023-03-01 03:33 出处:网络
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

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 IOExceptions 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 Sockets 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消