Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
This program calls send/receive after trying to connect to a non-existing DatagramSocket, it times out after 5 seconds without throwing a PortUnreachableException. Apple JDK 6 throws a PortUnreachableException immediately. import java.net.*; public class A1 { public static void main(String[] args) throws Exception { byte[] data = "hello".getBytes(); InetAddress iaddr = InetAddress.getByName("localhost"); DatagramSocket dgSocket = new DatagramSocket(); dgSocket.setSoTimeout(5000); dgSocket.connect(iaddr, 8080); DatagramPacket dgPacketOut = new DatagramPacket(data, data.length, iaddr, 8080); dgSocket.send(dgPacketOut); byte ibuf[] = new byte[1024]; DatagramPacket dgPacketIn = new DatagramPacket(ibuf, ibuf.length); dgSocket.receive(dgPacketIn); } }
|