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

时间:2022-03-22 15:15:56

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. 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.

一个侦听端口X的Verticle,当有人连接并发送数据时,它会打开一个客户端连接到预配置的TCP服务器。从此刻开始,直到任何对等端关闭连接,保持双向信道,数据在客户端到服务器之间上下流动,反之亦然。

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?

哪里是我的错误?

1 个解决方案

#1


5  

I just was missing to start the pumps. Then it worked.

我只是缺少启动泵。然后它奏效了。

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

#1


5  

I just was missing to start the pumps. Then it worked.

我只是缺少启动泵。然后它奏效了。

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