Using websockets on port 80

232 views
Skip to first unread message

saruk...@googlemail.com

unread,
Jul 1, 2013, 9:17:22 AM7/1/13
to ne...@googlegroups.com
In principle WebSockets can co-exist with other HTTP traffic over ports 80 and 443 and firewalls need not be reconfigured. But I fail to achieve binding to port 80 with the ServerBootstrap methods.

Could you please explain how can we bind a connection to port 80 using netty 4.0

Here's what I do at the moment:

                     ServerBootstrap bootstrap = new ServerBootstrap();
                     bootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup())
                    .channel(NioServerSocketChannel.class)
                    .childHandler(new WebSocketServerInitializerFactory());
                     Channel ch = bootstrap.bind(serverHost, port).sync().channel();


I use the above mentioned way (with serverHost as localhost and port = 80) and encounter the address already in use exception

java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:344)
at sun.nio.ch.Net.bind(Net.java:336)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:199)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:98)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:646)
at io.netty.channel.DefaultChannelPipeline$HeadHandler.bind(DefaultChannelPipeline.java:1296)
at io.netty.channel.DefaultChannelHandlerContext.invokeBind0(DefaultChannelHandlerContext.java:1026)
at io.netty.channel.DefaultChannelHandlerContext.invokeBind(DefaultChannelHandlerContext.java:1012)
at io.netty.channel.DefaultChannelHandlerContext.bind(DefaultChannelHandlerContext.java:1006)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:1072)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:250)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:332)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:328)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:331)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:109)
at java.lang.Thread.run(Thread.java:722)

Is there a way in which I can re-use port 80 that is already being used to serve http requests by Apache?

Thanks in advance.

Norman Maurer

unread,
Jul 1, 2013, 3:53:56 PM7/1/13
to ne...@googlegroups.com
If the port is bound by apache already there is no way to also use it for your Netty application.

---
Norman Maurer

JBoss, by Red Hat



--
 
---
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/groups/opt_out.
 
 

saruk...@googlemail.com

unread,
Jul 1, 2013, 6:43:50 PM7/1/13
to ne...@googlegroups.com, nma...@redhat.com
Thanks Norman. So how is it possible that WebSockets traffic can co-exist with normal http traffic at port 80 (or 443) as mentioned here - http://netty.io/news/2011/11/17/websockets.html ?

Kevin Burton

unread,
Jul 1, 2013, 8:22:04 PM7/1/13
to ne...@googlegroups.com, nma...@redhat.com
shutdown apache.

saruk...@googlemail.com

unread,
Jul 2, 2013, 5:40:18 AM7/2/13
to ne...@googlegroups.com, nma...@redhat.com
Thanks Kevin. In that case html pages of other existing services have to be served through Netty alone. Although that is not a problem, there is the convenience issue of embedding HTML and JS into Java variables in ClientHandlers. Is there a better way of serving client html that I am missing?

Rajiv Kurian

unread,
Jul 2, 2013, 5:42:06 PM7/2/13
to ne...@googlegroups.com
Netty supports zero copy file upload. Example: https://github.com/netty/netty/blob/3/src/main/java/org/jboss/netty/example/http/file/HttpStaticFileServerHandler.java
You could also set up proper forwarding rules to get Apache to handle file serving, but forward websocket traffic to Netty using some other port. Say from port 80 on Apache to port 8000 on Netty.
Message has been deleted

Rajiv Kurian

unread,
Jul 2, 2013, 5:43:32 PM7/2/13
to ne...@googlegroups.com
I meant zero copy file serving.

saruk...@googlemail.com

unread,
Jul 3, 2013, 10:05:25 AM7/3/13
to ne...@googlegroups.com
Ok great. Thanks for the pointer.
Reply all
Reply to author
Forward
0 new messages