문제

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