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)上。窗户和往常一样例外