int (InetAddress address) { ListeningConnection listeningConnection = new ListeningConnection(address); BuiltInServerManager builtInServerManager = BuiltInServerManager.getInstance(); builtInServerManager.waitForStart(); ServerBootstrap bootstrap = ((BuiltInServerManagerImpl)builtInServerManager).createServerBootstrap(); bootstrap.childHandler(new ChannelInitializer<>() { @Override protected void initChannel(@NotNull Channel channel) { channel.pipeline().addLast(listeningConnection.myChannelRegistrar, new ProtobufVarint32FrameDecoder(), new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()), new ProtobufVarint32LengthFieldPrepender(), new ProtobufEncoder(), myMessageDispatcher); } }); Channel serverChannel = bootstrap.bind(address, 0).syncUninterruptibly().channel(); listeningConnection.myChannelRegistrar.setServerChannel(serverChannel, false); int port = ((InetSocketAddress)serverChannel.localAddress()).getPort(); listeningConnection.myListenPort = port; myListeningConnections.add(listeningConnection); return port; }