更新时间:2022-02-10 22:18:30
Android的套接字.isConnected()
将返回true
而不是false
如果套接字
未正确断开连接(即未调用Socket.close
)。
我认为唯一保证知道Socket
是否还活着的方法是尝试写入并处理IOException
如果没有连接,它会抛出。
希望这会有所帮助,
Fredrik
Android'sSocket.isConnected()
will returntrue
instead offalse
if theSocket
was disconnected incorrectly (i.e. not callingSocket.close
).
I think the only guaranteed way of knowing if aSocket
is still alive is to try to write to it and handle theIOException
that it will throw if it is not connected.
Hope this helps,
Fredrik