2013-09-16 91 views
2

我已經看過關於這個問題的其他答案,但他們大多聲明在綁定套接字之前調用setReuseAddress (true)。但我正在這樣做,它仍然無法工作,有人可以幫我在這裏嗎?Android,setReuseAddress不起作用

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(); 

回答

0

它不適用於TCP,除非同一端口上的先前套接字綁定在不同於0.0.0.0的IP地址上。 Windows一如既往地例外。

+0

哦,好吧,我不知道,謝謝! – Fischa