我已经查看了有关此问题的其他答案,但他们大多声明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();