Reputation: 147
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?
Upvotes: 1
Views: 1734
Reputation: 311008
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.
Upvotes: 1