I'm working on a NIO client program on Android, Basically it functions well, but when the network is not avaliable(WIFI is disabled, etc), I have no idea how to distinguish the socket is 'really' connected, SocketChannel.finishConnect() always returns true even there is no avaliable network.If I try to write to a unconnected SocketChannel, an Broken pipe exception will happen.

So I wonder how to make sure the SocketChannel is really connected?

有帮助吗?

解决方案

If I try to write to a unconnected SocketChannel, an Broken pipe exception will happen.

Correct.

So I wonder how to make sure the SocketChannel is really connected?

That's how. There is no API that can tell you. TCP doesn't work like that. The only way to detect a broken TCP connection is to try to use it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top