Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7164518

No PortUnreachableException when connecting to a non-existing DatagramSocket (mac)

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Description

      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);
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                weijun Weijun Wang
              • Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported:
                  Indexed: