简体   繁体   English

Vert.x中使用Pump类(JAVA)的简单TCP代理

[英]Simple TCP proxy in Vert.x using Pump class (JAVA)

I would like to realize a proof of concept TCP transparent proxy in Vert.x. 我想在Vert.x中实现TCP透明代理的概念验证。

Requirement 需求

A verticle that listens on port X and when somebody connects and sends data it opens a client connection towards a preconfigured TCP server. 侦听端口X的Verticle,当有人连接并发送数据时,它会打开一个客户端连接,指向预配置的TCP服务器。 From this moment until any of the peers closes the connection, a bidirectional channel is kept and data flows up and down the channel from client to server and viceversa. 从此刻开始,直到任何对等体关闭连接,保持双向通道,数据在通道上从客户端到服务器上下流动,反之亦然。

Here's my attempt which is not working. 这是我的尝试无效。

 vertx.createNetServer().connectHandler(new Handler<NetSocket>() {
        public void handle(final NetSocket socket) {
            vertx.createNetClient().connect(6367, "localhost", new Handler<NetSocket>() {

                @Override
                public void handle(NetSocket cliSocket) {
                    Pump.createPump(socket, cliSocket);
                    Pump.createPump(cliSocket, socket);

                }
            });     
    }
    }).listen(3000);
}

At least this is how I understood the meaning of the Pump class: 至少这是我理解Pump类的含义:

http://vertx.io/core_manual_java.html#pump http://vertx.io/core_manual_java.html#pump

Where's my error? 哪里是我的错误?

I just was missing to start the pumps. 我只是缺少启动泵。 Then it worked. 然后它奏效了。

Pump.createPump(socket, cliSocket).start();
Pump.createPump(cliSocket, socket).start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM