如何使用Netty 3.8 ServerBootstrap(TCP)将消息从服​​务器写入IP /端口

时间:2017-11-13 14:12:49

标签: tcp apache-camel netty send

我想从服务器向IP /端口发送消息但是在写通道时它不起作用。我不确定我做错了什么。

    private Channel channel;
    private void createConnection() {

    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    this.bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new SimpleChannelHandler());
        }
    });
    bootstrap.setOption("localAddress", new InetSocketAddress("localhost", 0));
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("child.sendBufferSize", 65536);
    bootstrap.setOption("child.receiveBufferSize", 65536);
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);

    this.channel = bootstrap.bind();
}

我正在使用apache camel编写一个组件。当我的组件进程时,我希望它向IP /端口发送消息。

    public void send(Exchange exchange) {

    String ip = exchange.getIn().getHeader("ip", String.class);
    int port = exchange.getIn().getHeader("port", Integer.class);

    Object msg = exchange.getIn().getBody();
    InetSocketAddress inetSocketAddress = new InetSocketAddress(ip, port);

    this.channel.write(msg, inetSocketAddress);
}

我收到了“getUnsupportedOperationFuture”。我不确定我做错了什么。我正在使用Netty 3.8,我认为连接设置正确。有帮助吗?

0 个答案:

没有答案