Skip to main content

Module tcp_proxy

Module tcp_proxy 

Source
Expand description

Layer-4 TCP proxy.

TcpProxy accepts raw TCP connections and forwards them to backend servers, bidirectionally tunneling bytes with one thread per direction.

Unlike crate::proxy::ReverseProxy (which operates at the HTTP layer), TcpProxy is protocol-agnostic: any TCP-based protocol (database wire formats, custom binary protocols, raw TLS passthrough) is forwarded unchanged.

§Example

use rust_web_server::tcp_proxy::TcpProxy;

// Proxy raw TCP on port 5432 across two PostgreSQL backends.
TcpProxy::new(["backend-1:5432", "backend-2:5432"])
    .connect_timeout_ms(3000)
    .bind("0.0.0.0:5432")
    .unwrap();

Structs§

TcpProxy
Layer-4 (raw TCP) reverse proxy with round-robin load balancing.