Bind Jetty to IPv6 address

狂风中的少年 提交于 2019-12-31 01:52:15

问题


I am trying to bind Jetty to listen only to IPv6 address. I am using Jetty 7.4.2.v20110526.

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

the error I get:

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)

I have tried both ::1 and [::1]

How can I bind Jetty to IPv6 address? Is IPv6 supported by Jetty at all?


回答1:


If you haven't found a solution, here it is. Change the NIO connector with the IO one. Instead of using "org.mortbay.jetty.nio.SelectChannelConnector" use "org.mortbay.jetty.bio.SocketConnector" and the overall connector config will be:

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

This way you will be able to access the webpage using both IPv4 and IPv6 address. Hope this helps.




回答2:


Old versions of the Sun JRE do not support IPv6 on NIO channels, so simply upgrade the JVM.

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



来源:https://stackoverflow.com/questions/7023523/bind-jetty-to-ipv6-address

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!