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