在我的 Android 项目中,我实现了一个 Faye 客户端。但是,当我打电话时SocketChannel.socket().connect(...)
,连接挂起并且下一行没有运行。好像我没有设置超时,或者断开超时。
Thread.currentThread().setName("WebSocketConnector");
try {
// "java.net.SocketException: Address family not supported by protocol"
System.setProperty("java.net.preferIPv6Addresses", "false");
mTransportChannel = SocketChannel.open();
// mTransportChannel.configureBlocking(false);
// the following will block until connection was established or
// an error occurred!
mTransportChannel.socket().connect(
new InetSocketAddress(mWsHost, mWsPort), mOptions.getSocketConnectTimeout());
Log.i(TAG, "Socket connected");
// before doing any data transfer on the socket, set socket
// options
mTransportChannel.socket().setSoTimeout(
mOptions.getSocketReceiveTimeout());
mTransportChannel.socket().setTcpNoDelay(
mOptions.getTcpNoDelay());
return null;
} catch (IOException e) {
Log.e(TAG, e.getMessage());
return e.getMessage();
}
如果我这样做了:
mTransportChannel = SocketChannel.open();
mTransportChannel.configureBlocking(false);
mTransportChannel.connect(socketAddress);
SocketChannel .isConnected() return false
我不明白的问题是什么?