其实这个问题不光是
ServerSocketChannel,还有SocketChannel connect一ipv6地址时,同样产生异常
代码如下:
protected final ServerSocketChannel ssc;
private int ListenPort=8088;
...
this.ssc = ServerSocketChannel.open();
this.ssc.configureBlocking(false);
local6Address=(Inet6Address)Inet6Address.getByName("2001:250:f007:1:f1ea:dada:9b57:9596");
InetSocketAddress inetSocketAddress=new InetSocketAddress(local6Address,this.ListenPort);try {
       this.ssc.socket().bind(inetSocketAddress);
    }catch (IOException e){
       System.err.println("the socket exception");
       e.printStackTrace();
    }产生异常:
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)

解决方案 »

  1.   

    这个问题没有人碰到吗?
    还是没有人会解决?
    我这个程序运行在xp  sp2系统上
      

  2.   

    问题解决没有。我也遇到了类似的问题。感觉好像J2SE不能使用windowsXP下的IPv6协议。
      

  3.   

    问题没有解决,我感觉是nio的ServerSocketChannel和SocketChannel有问题,其实如果不用这两个东西直接使用ServerSocket和Socket就可以建立连接。
      

  4.   

    真的?我这里的问题,可能不是你那样的。
    我是使用了DatagramSocket来建立连接,结果总是无法取得IPv6的地址连接。
    即使本地的也失败。
    你有mail吗?我的mail是[email protected]
    可以否?
      

  5.   

    说错了,应该说是无法绑定。而用IPv4的DatagramSocket则没有问题。端口可以绑定。
      

  6.   

    刚才换了一个函数,没有继续采用DatagramSocket(port,InetAddress)来绑定,居然成功了,
    而且,IPv4的地址和IPv6的地址同时被绑定了。可以同时使用。
      

  7.   

    这个问题我感觉是java的bug,使用(Inet6Address)Inet6Address.getByName("2001:250:f007:1:f1ea:dada:9b57:9596");得到的就是ipv4地址,所以我个人认为是bug希望sun能在1.6中解决掉这个问题。
    我的email
    [email protected]

    [email protected]