Android,setReuseAddress不起作用

时间:2013-09-16 12:09:12

标签: 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.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();

1 个答案:

答案 0 :(得分:0)

除非同一端口上的先前套接字绑定在不同的IP地址(0.0.0.0除外)上,否则它不适用于TCP。 Windows一如既往地排除。