Android 为什么在SocketChannel中连接不在非阻塞模式下运行?

Android 为什么在SocketChannel中连接不在非阻塞模式下运行?,android,Android,我试图打开不同主机的套接字,为此我在非阻塞模式下使用SocketChannel: ListIterator iter = hosts.listIterator(); SocketChannel sChannel = null; while (iter.hasNext()) { Host host = iter.next(); sChannel = SocketChannel.open(); sChannel.configureBlocking(false); s

我试图打开不同主机的套接字,为此我在非阻塞模式下使用SocketChannel:

ListIterator iter = hosts.listIterator();
SocketChannel sChannel = null;
while (iter.hasNext()) 
{
    Host host = iter.next();
    sChannel = SocketChannel.open();
    sChannel.configureBlocking(false);
    sChannel.connect(new InetSocketAddress(host, 80));
}
然后我打电话给finishConnect


问题是连接似乎被阻塞。

我在android上看到了同样的行为。无论InetSocketAddress是否通过以下方式实例化,都会出现此问题

新的InetSocketAddressString主机,int端口 新InetSocketAddress InetAddress.getByAddress字节[]ipAddress 新InetSocketAddress InetAddress.getByAddress字符串主机,字节[]ipAddress 我看到的堆栈如下所示

InetAddress.gethostbyaddr(byte[]) line: not available [native method]   
InetAddress.getHostByAddrImpl(byte[]) line: 558 
Inet4Address(InetAddress).getHostName() line: 352   
SocketChannelImpl.connect(SocketAddress) line: 259  
ScannerTargetAuxillaryTest.runBusinessUseCase(InetSocketAddress[]) line: 38 
ScannerTargetAuxillaryTest.testVersion2() line: 125 
ScannerTargetAuxillaryTest.main() line: 247 
TestActivity.onCreate(Bundle) line: 46  
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2466  
ActivityThread.handleLaunchActivity(ActivityThread$ActivityRecord, Intent) line: 2519   
ActivityThread.access$2200(ActivityThread, ActivityThread$ActivityRecord, Intent) line: 123 
ActivityThread$H.handleMessage(Message) line: 1870  
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 4370    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 521  
ZygoteInit$MethodAndArgsCaller.run() line: 868  
ZygoteInit.main(String[]) line: 626 
NativeStart.main(String[]) line: not available [native method]  

您发布的代码显示您在循环中声明了sChannel。你怎么可能稍后打电话给finishConnect?或者使用这些频道