在我的Android项目中,我实现了一个Faye客户端。但是,当我拨打SocketChannel.socket().connect(...)
时,连接挂起,下一行不运行。就好像我不设置超时,或者超时断开连接。Android连接到WebSocket hang
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
什么问题我不明白?
InetSocketAddress socketAdd = new InetSocketAddress(“172.20.71.4”,9292); boolean resolve = socketAdd.isUnresolved(); 在socketAdd主机null和端口9292,为什么?并解决错误 – JULI
在命令行尝试'telnet 172.20.71.4 9292'。那样有用吗? –