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

networking - error in socet bind example

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 6-pool
    • docs
    • b34
    • generic
    • generic
    • Not verified

      The following url:
      http://download.oracle.com/javase/tutorial/networking/nifs/definition.html

      Stipulates that you can easily use the “NetworkInterface” class in the following manner:

          NetworkInterface nif = NetworkInterface.getByName("bge0");
          Enumeration nifAddresses = nif.getInetAddresses();
          Socket soc = new java.net.Socket ();
          soc.bind (nifAddresses.nextElement ());
          soc.connect (new InetSocketAddress (address, port));

      The bind method does not, as yet, accept “InetAddress” as a parameter. The correct code thus, is still:
          soc.bind ((SocketAddress) new InetSocketAddress (nifAddresses.nextElement (), 0));

      Also, in light of stricter rules, I think the following line be replaced,
          Enumeration nifAddresses = nif.getInetAddresses();

      with:

          Enumeration <InetAddress> nifAddresses = nif.getInetAddresses ();

            sharonz Sharon Zakhour (Inactive)
            skannan Sowmya Kannan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: