将Jetty绑定到IPv6地址

时间:2011-08-11 09:19:01

标签: jetty ipv6

我正在尝试绑定Jetty以仅侦听IPv6地址。我使用的是Jetty 7.4.2.v20110526。

我的jetty.xml:

<Call name="addConnector">
  <Arg>
      <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
        <Set name="host">::1</Set>
        <Set name="port"><SystemProperty name="jetty.port" default="8070"/></Set>
        <Set name="maxIdleTime">30000</Set>
        <Set name="Acceptors">2</Set>
        <Set name="confidentialPort">8443</Set>
      </New>
  </Arg>
</Call>    

我得到的错误:

java.net.SocketException@3d3c4c09: Address family not supported by protocol family: bind; 
at sun.nio.ch.Net.bind(Native Method)
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 org.eclipse.jetty.server.nio.SelectChannelConnector.open(SelectChannelConnector.java:172)
at org.eclipse.jetty.server.AbstractConnector.doStart(AbstractConnector.java:297)
at org.eclipse.jetty.server.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:250)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:269)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)

我已经尝试了::1[::1]

如何将Jetty绑定到IPv6地址? Jetty是否支持IPv6?

2 个答案:

答案 0 :(得分:3)

如果您还没有找到解决方案,请点击此处。使用IO改变NIO连接器。而不是使用“ org.mortbay.jetty.nio.SelectChannelConnector ”使用“ org.mortbay.jetty.bio.SocketConnector ”,整个连接器配置将是:

<Call name="addConnector">
  <Arg>
      <New class="org.mortbay.jetty.bio.SocketConnector">
        <Set name="port"><SystemProperty name="jetty.port" default="8070"/></Set>
        <Set name="maxIdleTime">50000</Set>
        <Set name="lowResourceMaxIdleTime">1500</Set>
      </New>
  </Arg>
</Call>

这样您就可以使用IPv4和IPv6地址访问网页。希望这会有所帮助。

答案 1 :(得分:2)

旧版本的Sun JRE在NIO通道上不支持IPv6,因此只需升级JVM即可。

http://bugs.sun.com/view_bug.do?bug_id=6230761