WebSocket Proxy Server
TsgcWebSocketProxyServer — accepts WebSocket connections from clients (typically browsers) and forwards data to a plain TCP/IP server. The cleanest way to expose a legacy TCP backend to a modern browser front-end.
TsgcWebSocketProxyServer — accepts WebSocket connections from clients (typically browsers) and forwards data to a plain TCP/IP server. The cleanest way to expose a legacy TCP backend to a modern browser front-end.
Bridges the WebSocket protocol gap so browsers can talk to plain TCP servers.
TsgcWebSocketProxyServer implements a WebSocket Server component that listens for client WebSocket connections and forwards data to a normal TCP/IP server. This is especially useful for browser connections because it lets a browser virtually connect to any TCP service that does not natively speak WebSocket.
Drop the proxy in front of legacy TCP services — SMTP relays, IRC servers, custom binary protocols, telnet endpoints, or proprietary trading feeds — and serve them to a JavaScript or browser-based client without rewriting the backend.
The proxy accepts the WebSocket handshake from the browser as any standard sgcWebSockets server would — HTTP upgrade, optional sub-protocols, optional TLS via wss:// for end-to-end encryption between browser and proxy.
For each accepted client the proxy opens a corresponding TCP connection to the configured backend host and port. WebSocket frames received from the browser are unwrapped and written to the TCP socket; bytes received from the backend are wrapped into WebSocket frames and pushed to the browser.
The proxy tracks the lifecycle of both sockets. Closing the WebSocket side closes the TCP side and vice versa. Use the standard sgcWebSockets server events (OnConnect / OnDisconnect / OnMessage / OnError) to log, authenticate or filter the bridged traffic.
Bridge a browser WebSocket client to a TCP backend.
// Drop a TsgcWebSocketProxyServer on the form
// Listen for incoming WebSocket connections
sgcWebSocketProxyServer1.Host := '0.0.0.0';
sgcWebSocketProxyServer1.Port := 443;
// Optional: secure browser connections with TLS (wss://)
sgcWebSocketProxyServer1.SSL := True;
sgcWebSocketProxyServer1.SSLOptions.CertFile :=
'server.crt';
sgcWebSocketProxyServer1.SSLOptions.KeyFile :=
'server.key';
// Forward all bridged traffic to the TCP backend
sgcWebSocketProxyServer1.Proxy.Host := 'backend.internal';
sgcWebSocketProxyServer1.Proxy.Port := 25;
sgcWebSocketProxyServer1.Active := True;
// Browser side (JavaScript)
// const ws = new WebSocket('wss://proxy.example.com');
// ws.onopen = () => ws.send('HELO browser');
// ws.onmessage = ev => console.log(ev.data);
Expose a legacy TCP service (binary protocol, custom server, MUD, IRC) to a modern browser without rewriting the backend.
Some environments only allow ports 80 / 443. Front a backend TCP service with the proxy on 443/wss so corporate clients can reach it through restrictive egress.
Browser-based terminal, remote shell or telnet client — the browser opens a WebSocket and the proxy bridges it to the underlying TCP server.
The TCP backend speaks plaintext. Front it with the proxy on wss:// so the browser sees TLS while the backend connection stays simple.