tcp2ws

package module
v0.0.0-...-a42fd90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License: BSD-3-Clause Imports: 9 Imported by: 0

README

tcp2ws

tcp2ws is a Go-based tool that provides bidirectional TCP to WebSocket protocol conversion. It consists of two commands that allow you to:

  1. Forward TCP connections to a WebSocket server (tcp2ws)
  2. Forward WebSocket connections to a TCP server (ws2tcp)

This enables TCP-only clients to communicate with WebSocket servers and vice versa, making it useful for scenarios where protocol conversion is needed, such as connecting legacy TCP applications to modern WebSocket services.

Requirements

  • Go 1.21 or later

Installation

go install github.com/oxplot/tcp2ws/cmd/tcp2ws@latest
go install github.com/oxplot/tcp2ws/cmd/ws2tcp@latest

Usage

tcp2ws

tcp2ws listens for TCP connections and forwards them to a WebSocket server.

tcp2ws [options] ws[s]://host:port/path

Options:
  -listen string
        TCP listen address:port (default ":7101")

Example:

# Forward TCP connections from port 7101 to a WebSocket server
tcp2ws -listen :7101 ws://example.com:8080/ws
ws2tcp

ws2tcp runs a WebSocket server that forwards connections to a TCP server.

ws2tcp [options] tcp-host:port

Options:
  -listen string
        WebSocket listen address:port (default ":8080")

Example:

# Accept WebSocket connections on port 8080 and forward them to a TCP server
ws2tcp -listen :8080 localhost:6379

Features

  • Bidirectional data forwarding between TCP and WebSocket protocols
  • Support for both ws:// and wss:// (secure WebSocket) protocols
  • Configurable listen addresses and ports
  • Automatic connection cleanup and resource management
  • Error handling and logging

Documentation

Overview

Package tcp2ws provides functions to forward TCP connections to WebSocket servers and vice versa.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForwardTCP

func ForwardTCP(ctx context.Context, tcpConn net.Conn, websocketURL string) error

ForwardTCP handles a TCP connection and forwards it to a WebSocket server. Handle blocks until the connection is closed or ctx is canceled.

func ForwardWebsocket

func ForwardWebsocket(w http.ResponseWriter, r *http.Request, tcpAddr string)

ForwardWebsocket handles a WebSocket connection and forwards it to a TCP server.

func Pipe

func Pipe(ctx context.Context, ws *websocket.Conn, tcp net.Conn, wsPing bool) error

Pipe forwards data between a WebSocket connection and a TCP connection.

Types

This section is empty.

Directories

Path Synopsis
cmd
tcp2ws command
ws2tcp command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL