Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > NIO + IPv6 + Windows XP (SP2) + jdk 1.5.0_01 => Problem ?

Reply
Thread Tools

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

 
 
d_pieroux@yahoo.com
Guest
Posts: n/a
 
      02-16-2005
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(ServerSock etChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAd aptor.java:59)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAd aptor.java:52)
at external.ipv6.main(ipv6.java:31)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between J2EE, JDK, JDK-SDK, JRE and J2SE packages ? Ulf Meinhardt Java 0 08-10-2006 07:12 PM
Ipv6 on a ipv4/ipv6 hostname Jesse van den Kieboom Ruby 1 06-05-2005 12:57 PM
jEdit: compiles JDK 1.5.0 ok, but runs JDK 1.4.1 (why?) Thomas G. Marshall Java 5 08-06-2004 04:12 AM
NIO with timeouts != NIO? iksrazal Java 1 06-18-2004 02:28 PM
Help with converting IDS from JDK 1.1 to JDK 1.4 Babar Java 1 05-20-2004 09:11 PM



Advertisments