Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android,setReuseAddress不';行不通_Java_Android_Sockets_Tcp - Fatal编程技术网

Java Android,setReuseAddress不';行不通

Java Android,setReuseAddress不';行不通,java,android,sockets,tcp,Java,Android,Sockets,Tcp,我已经看过了关于这个问题的其他答案,但它们大多表示在绑定套接字之前调用setReuseAddress(true)。但我正在这么做,但仍然不起作用,有人能帮我吗 SocketChannel tunnel = SocketChannel.open(); if (!protect(tunnel.socket())){ throw new IllegalStateException("Can not protect tunnel");} Log.i("TAG", "test"); tunnel.so

我已经看过了关于这个问题的其他答案,但它们大多表示在绑定套接字之前调用
setReuseAddress(true)
。但我正在这么做,但仍然不起作用,有人能帮我吗

SocketChannel tunnel = SocketChannel.open();

if (!protect(tunnel.socket())){
throw new IllegalStateException("Can not protect tunnel");}

Log.i("TAG", "test");
tunnel.socket().setReuseAddress(true);
tunnel.socket().bind(new InetSocketAddress(localAddress, localPort));
Log.i("TAG", "bind test");
tunnel.connect(new InetSocketAddress(destAddress, destPort));
tunnel.configureBlocking(false);

packet.position(0);
packet.limit(length);
Log.i("TAG", "schreibe: " + tunnel.write(packet));
packet.clear();

它不适用于TCP,除非同一端口上的前一个套接字绑定在不同的IP地址(不包括0.0.0.0)上。窗户和往常一样例外