我正在使用netty + udt + rendezvous测试此示例的修改版本: http://netty.io/4.0/xref/io/netty/example/udt/echo/rendezvous/package-summary.html
我已在我的服务器和本地计算机上启动了一个实例,其中" self" -host是双方的本地主机,而#34; peer" -host是另一个的主机名。因此A绑定到localhost并连接到B和B绑定到localhost并连接到A.
在局域网中,一切正常,但是当我连接位于防火墙(fritzbox路由器)和我的服务器后面的计算机时,一切正常(服务器不会阻塞端口)。在这种情况下会发生超时:
双方都看到了:
java -jar out/artifacts/LearningJavaAgain_jar/LearningJavaAgain.jar <host_name>
Jul 31, 2014 3:23:34 PM io.netty.handler.logging.LoggingHandler channelRegistered
INFORMATION: [id: 0xdd7790d7] REGISTERED
Jul 31, 2014 3:23:34 PM io.netty.handler.logging.LoggingHandler connect
INFORMATION: [id: 0xdd7790d7] CONNECT(xx.xxx.xxx.xxx:5555, localhost/127.0.0.1:5555)
Jul 31, 2014 3:24:04 PM io.netty.handler.logging.LoggingHandler close
INFORMATION: [id: 0xdd7790d7] CLOSE()
Exception in thread "main" io.netty.channel.ConnectTimeoutException: connection timed out: xx.xxx.xxx.xxx:5555
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe$1.run(AbstractNioChannel.java:214)
at io.netty.util.concurrent.PromiseTask$RunnableAdapter.call(PromiseTask.java:38)
at io.netty.util.concurrent.ScheduledFutureTask.run(ScheduledFutureTask.java:123)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:370)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
at java.lang.Thread.run(Thread.java:745)
Jul 31, 2014 3:24:04 PM io.netty.handler.logging.LoggingHandler channelUnregistered
INFORMATION: [id: 0xdd7790d7] UNREGISTERED
我认为netty + udt会用udp打孔,不是吗?
答案 0 :(得分:1)
没关系。当然,从其他计算机连接时,您必须使用0.0.0.0而不是localhost。我希望这对其他人也有帮助。它现在都很棒。