NIO + IPv6 + Windows XP (SP2) + jdk 1.5.0_01 => Problem ?

Discussion in 'Java' started by d_pieroux@yahoo.com, Feb 16, 2005.

  1. Guest

    Hello everybody,

    In the _sample_ code below, I listen on port 8501 using a ServerSocket
    instance and on port 8502 by going through a NIO ServerSocketChannel.

    Using jdk-1.5.0_01 (and the jre that comes embedded with it), this code
    works fine on Linux and Solaris boxes. However, running it on a Windows
    XP SP2 machine (with ipv6 installed and running and with no other older
    Java left installed), the attempt to go through the NIO channel throws
    a java.net.SocketException "Address family not supported by protocol
    family" exception.

    Strangely enough, binding the ServerSocket instance works, as
    demonstrated by the code output. (using netstat -a also shows that
    the port is listening). So, the probleme is not IPv6 by itself, but
    using it via an NIO server socket channel.

    Any idea ?
    D.P.

    (Note: this post is a repost from the Socket Java forum of Sun)

    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
    import java.nio.channels.ServerSocketChannel;

    class ipv6 {
    static public void main(String[] notUsed) {
    try {
    byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    1};

    InetAddress inetAddr = InetAddress.getByAddress(addr);

    InetSocketAddress addr_8501 = new
    InetSocketAddress(inetAddr, 8501);
    InetSocketAddress addr_8502 = new
    InetSocketAddress(inetAddr, 8502);

    System.out.println("==> 1");

    ServerSocket serverSocket = new ServerSocket();
    serverSocket.bind(addr_8501); // This works

    System.out.println("==> 2");

    ServerSocketChannel channel = ServerSocketChannel.open();
    channel.socket().bind(addr_8502); //This does not work on
    the Windows XP box.

    System.out.println("==> 3");
    } catch (Throwable t) {
    t.printStackTrace();
    }
    }
    }



    Running it on the Windows box results in:

    ==> 1
    ==> 2
    java.net.SocketException: Address family not supported by protocol
    family: bind
    at sun.nio.ch.Net.bind(Native Method)
    at
    sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:52)
    at external.ipv6.main(ipv6.java:31)
     
    , Feb 16, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. George
    Replies:
    5
    Views:
    784
    =?Utf-8?B?S2VuIEJlYXJk?=
    Aug 24, 2004
  2. iksrazal

    NIO with timeouts != NIO?

    iksrazal, Jun 17, 2004, in forum: Java
    Replies:
    1
    Views:
    6,280
    iksrazal
    Jun 18, 2004
  3. Replies:
    2
    Views:
    2,245
  4. lightning
    Replies:
    3
    Views:
    522
    Oliver Wong
    Apr 16, 2007
  5. Jesse van den Kieboom

    Ipv6 on a ipv4/ipv6 hostname

    Jesse van den Kieboom, Jun 5, 2005, in forum: Ruby
    Replies:
    1
    Views:
    364
    Dibya Prakash
    Jun 5, 2005
Loading...

Share This Page