Android 中出现java.net.BindException: bind failed: EADDRINUSE 问题解决办法
看下问题:
try{DatagramSocket udpSocket = new DatagramSocket(DEFAULT_PORT );} catch (Exception e){e.printStackTrace();}//java.net.BindException: bind failed: EADDRINUSE (Address already in use)
解决方法:
将:udpSocket = new DatagramSocket(DEFAULT_PORT );
改为:
if(udpSocket==null){udpSocket = new DatagramSocket(null);udpSocket.setReuseAddress(true);udpSocket.bind(new InetSocketAddress(DEFAULT_PORT));}
问题就解决了
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
新闻热点
疑难解答