EpollServerSocketChannel always return 0 for binding to port 0?

58 views
Skip to first unread message

Reynold Xin

unread,
Aug 13, 2014, 2:59:34 PM8/13/14
to ne...@googlegroups.com
I'm testing EpollServerSocketChannel and found that the port returned by it after binding is always 0. Is this expected? This is with Netty 4.0.17-Final

val bossGroup = new io.netty.channel.epoll.EpollEventLoopGroup(1)
val workerGroup = new io.netty.channel.epoll.EpollEventLoopGroup(0)
val bootstrap = new io.netty.bootstrap.ServerBootstrap
bootstrap.group(bossGroup, workerGroup).channel(classOf[io.netty.channel.epoll.EpollServerSocketChannel]).childHandler(new io.netty.channel.ChannelInitializer[io.netty.channel.socket.SocketChannel] {
      override def initChannel(ch: io.netty.channel.socket.SocketChannel): Unit = {
      }
    })
val cf = bootstrap.bind(new java.net.InetSocketAddress(12345))
cf.sync()

println("local address is " + cf.channel.localAddress)

This always prints "local address is 0.0.0.0/0.0.0.0:0"

If I replace Epoll with Nio, the output works:

val bossGroup = new io.netty.channel.nio.NioEventLoopGroup(1)
val workerGroup = new io.netty.channel.nio.NioEventLoopGroup(0)
val bootstrap = new io.netty.bootstrap.ServerBootstrap
bootstrap.group(bossGroup, workerGroup).channel(classOf[io.netty.channel.socket.nio.NioServerSocketChannel]).childHandler(new io.netty.channel.ChannelInitializer[io.netty.channel.socket.SocketChannel] {
      override def initChannel(ch: io.netty.channel.socket.SocketChannel): Unit = {
      }
    })

val cf = bootstrap.bind(new java.net.InetSocketAddress(0))
cf.sync()
println("local address is " + cf.channel.localAddress)

local address is /0:0:0:0:0:0:0:0:44569




Norman Maurer

unread,
Aug 13, 2014, 3:07:59 PM8/13/14
to ne...@googlegroups.com, Reynold Xin
Hey Reynold,

this was fixed in a later release. So upgrade to latest stable should fix this for you.
-- 
Norman Maurer
--

---
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reynold Xin

unread,
Aug 13, 2014, 3:11:21 PM8/13/14
to ne...@googlegroups.com, rx...@databricks.com
Thanks. Will give the latest release a try.

Norman Maurer

unread,
Aug 13, 2014, 3:30:41 PM8/13/14
to ne...@googlegroups.com, rx...@databricks.com
Let us know if you have any issues
Reply all
Reply to author
Forward
0 new messages