本文介绍了Netty-使用与绑定服务器通道相同的侦听地址来启动新连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定的服务器通道,该通道当前正在本地地址'x'接受连接.现在,我需要启动到远程地址"y"的连接,但我也需要将本地侦听地址也设置为"x".当使用本地通道工厂和本地地址时,当我尝试使用本地地址="x"建立新的客户端连接时,出现地址已绑定"错误.这是有道理的.

I have a bound server channel that is currently accepting connections at local address 'x'. I now need to initiate a connection to a remote address 'y', but I need my local listening address to be 'x' as well. When working with the local channel factory and local addresses, I get a 'address already bound' error when I try to make a new client connection with local address = 'x'. This makes sense.

因此,我的下一条路线是尝试找到一种从服务器通道创建新的子连接的方法,但这最终使netty内部代码过于深入,似乎是一条糟糕的路线.我记得以前曾见过一个有关本地客户端连接的错误.

So my next route was trying to find a way to create a new child connection from the server channel, but this ended up going a little too deep into the netty internal code and seemed like a bad route to go. I remember seeing a bug earlier about local client connections.

  • 这仅仅是本地渠道的错误吗?
  • 是否可以从Netty中的绑定地址发起连接?

谢谢,丹尼尔

推荐答案

您正在编写代理吗?如果是这样,这是一个netty 示例应用.

Are you writing a proxy? If so, here's a netty example app.

请注意,您必须为客户端和服务器设置不同的通道工厂.

Note that you have to setup different channel factories for client and server.

    // Configure the bootstrap.
    Executor executor = Executors.newCachedThreadPool();
    ServerBootstrap sb = new ServerBootstrap(
            new NioServerSocketChannelFactory(executor));

    // Set up the event pipeline factory.
    ClientSocketChannelFactory cf =
            new NioClientSocketChannelFactory(executor);

这篇关于Netty-使用与绑定服务器通道相同的侦听地址来启动新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 16:36