Android 中出現(xiàn)java.net.BindException: bind failed: EADDRINUSE 問題解決辦法
更新時間:2017年04月28日 10:12:58 投稿:lqh
這篇文章主要介紹了Android 中出現(xiàn)java.net.BindException: bind failed: EADDRINUSE 問題解決辦法的相關(guān)資料,需要的朋友可以參考下
Android 中出現(xiàn)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));
}
問題就解決了
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
朋友圈實現(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)
下面小編就為大家?guī)硪黄笥讶崿F(xiàn)圖片+文字轉(zhuǎn)發(fā)功能(必看篇)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
2017-03-03 
