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

DatagramSocket/DatagramChannel::connect and DatagramSocket/DatagramChannel::send could explicitly use localhost when the specified peer address is the wildcard

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • core-libs
    • None

      Rather than relying on undocumented kernel specific behavior, DatagramSocket::connect and DatagramSocket::send could explicitly use localhost when the specified peer address is the wildcard (and same for DatagramChannel and its socket adaptor).

      This would allow to do things like:

      var listener = new DatagramSocket(0);
      var sender = new DatagramSocket(0);
      var packet = new DatagramPacket(buf, buf.length);
      sender.connect(listener.getLocalSocketAddress());
      sender.send(packet);

      which currently only works on mac when -Djava.net.preferIPv4Stack is specified.

            dfuchs Daniel Fuchs
            dfuchs Daniel Fuchs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: