在我的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'。那樣有用嗎? –