I'm testing a modified version of this example using netty + udt + rendezvous: http://netty.io/4.0/xref/io/netty/example/udt/echo/rendezvous/package-summary.html
I've started an instance on both my server and my local machine where the "self"-host is localhost on both sides and the "peer"-host is the host name of the other. So A binds to localhost and connects to B and B binds to localhost and connects to A.
In LAN everything works fine but not when I connect my computer, which sits behind a firewall (fritzbox router) and my server.(The server does not block the port). In this case a timeout happens:
On both sides I see:
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
I thought that netty+udt does udp hole punching, doesn't it ?
Never mind. Of course you have to use 0.0.0.0 instead of localhost when connecting from a different machine. I hope this helps other people, too. It works all great now.