java.net.BindException: bind failed: EADDRINUSE (Address already in use)
[E/NMPWIFI ( 1189): java.net.BindException: bind failed: EADDRINUSE (Address already in use)W/System.err( 1189): java.net.BindException: bind failed: EADDRINUSE
最近项目使用UDP通信,遇到了绑定异常的情况:udp端口调用close 后不及时释放的问题 ,(原因是多次new udpsocket 第一个虽然调用close 但是系统不及时关闭,有延迟 ,在第二次new 的时候就会报端口被占用的错误
if (datagramSocket ==null) {
datagramSocket =new DatagramSocket(port);
DatagramPacket datagramPacket =new DatagramPacket(message, message.length);
datagramSocket.setSoTimeout(165000);
datagramSocket.receive(datagramPacket);
}