tcp-proxy

Forward TCP requests hitting a specified port on the localhost to a different port on another host

Both IPv4 and IPv6 are supported. On Linux splice is used to improve perf, details can be found here.

 USAGE:
     ./zig-out/bin/tcp-proxy [OPTIONS]

 OPTIONS:
  -b, --bind_host STRING           Local bind host(default: 0.0.0.0)
  -p, --local_port INTEGER         Local bind port(default: 8081)
  -H, --remote_host STRING         Remote host(required)
  -P, --remote_port INTEGER        Remote port(required)
      --buf_size INTEGER           Buffer size for tcp read/write(default: 16384)
      --server_threads INTEGER     Server worker threads num(default: 24)
  -h, --help
  -v, --version
      --verbose
1
tcp-proxy -b 0.0.0.0 -p 8082 -H 192.168.0.2 -P 8082

This will forward tcp requests from localhost:8082 to 192.168.0.2:8082

Benchmark

iPerf3 is used to benchmark performance between zigcli and this, a proxy written in C.

All in one

server/client/proxy
192.168.31.142, debian 12
senderreceiver
zigcli57.256.9
proxy in C56.155.9
  • Unit: Gbits/sec

Server/client separated

server
192.168.31.94, macOS
proxy/client
192.168.31.142, debian 12
senderreceiver
zigcli191180
proxy in C210198
  • Unit: Mbits/sec

Commands

1
2
3
4
5
6
7
8
9
# start C proxy in foreground
./proxy -b 0.0.0.0 -l 8081 -h 192.168.31.142 -p 5201 -f
# start tcp-proxy
./zig-out/bin/tcp-proxy -b 0.0.0.0 -p 8080 -H 192.168.31.142 -P 5201

# server
iperf3 -s
# client
iperf3 -c 192.168.31.142 -p 8080/8081
Last modified September 28, 2024: refactor zip file directory structure (9e01903)