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

D

d_pieroux

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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top