开发者

Writing to a java socket channel which should be closed does not generate an exception

We have a java server that keeps a socket channel open with an Android client in order to provide push capabilities to our client application.

However, after putting the Android in airplane mode, which I expected would sever the connection, the server can still write to the SocketChannel object associated with that Android client and no error is thrown. Calling SocketChannel.isConnected() before writing to it returns true.

开发者_如何学C

What are we missing? Is the handling of sockets different with mobile devices?

Thanks in advance for your help.


SocketChannel.socket().isConnected() and SocketChannel.isConnected() return false before the socket is connected. Once the socket is connected they will return true, they will not revert to false for any reason.

SocketChannel.isOpen() returns true until you call SocketChannel.socket().close() or SocketChannel.close(). Once you have called close() on the socket, SocketChannel.isOpen() will return false, no other event will cause it to return false.

SocketChannel.socket().isClosed() returns false until you call SocketChannel.socket().close() or SocketChannel.close(). Once you have called close() on a socket - SocketChannel.socket().isClosed() will return true, no other event will cause it to return true.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜