首页 > 解决方案 > Run Netty and tomcat on same port but different ip in a single server (Netty opens at localhost)

问题描述

Have a server with 2 IP address(suppose 1.1.1.a and 1.1.1.b) Trying to configure the jar that is using netty so that it creates the WebSocket at 443 port. The server also hosts a tomcat that uses 443. Now tried to configure the netty to 1.1.1.a:443 and tomcat to 1.1.1.b:443.

        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);           
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .localAddress(new InetSocketAddress("1.1.1.a", 443))
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new HTTPInitializer());

        channel = b.bind(443).sync().channel();

But still, the netty is trying to start at 0.0.0.0:443 causing Bind Exception. Is it possible to configure in such a way? and if so what should be done?

标签: tomcatnetty

解决方案


Sure ... just use bind(new InetSocketAddress("1.1.1.a",443)


推荐阅读