[問題] DataGramSocket 不會丟 PortUnreachableException
我想寫程式檢查某個 UDP port 有沒有開
J2SE 6 的文件說用先呼叫 connect 後就會丟 PortUnreachable
程式片段如下
try{
DatagramSocket udp=new DatagramSocket();
DatagramPacket packet=new DatagramPacket(data,data.length);
udp.setSoTimeout(to);
udp.connect(ip,port);
udp.send(packet);
udp.close();
}catch(Exception e)
{
e.printStackTrace();
}
去連一個沒有開啟的 port 時,用 wireshark 看的確有 icmp 回來
但是並沒有 exception 請問是哪裡寫錯嗎?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.242.140
推
03/05 16:01, , 1F
03/05 16:01, 1F
推
03/05 16:43, , 2F
03/05 16:43, 2F
→
03/05 16:48, , 3F
03/05 16:48, 3F
→
03/05 16:51, , 4F
03/05 16:51, 4F
推
03/05 17:00, , 5F
03/05 17:00, 5F
→
03/05 17:55, , 6F
03/05 17:55, 6F
推
03/05 23:40, , 7F
03/05 23:40, 7F