Skip to content

Commit

Permalink
Add usage instructions with Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
IngmarStein committed May 24, 2024
1 parent 97d220d commit a084863
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
47 changes: 27 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

# tcp-multiplexer

Use it in front of target server and let your client programs connect it, if target server **only allows you to create limited tcp connections concurrently**. While it has its limitation: increased latency as incoming request will block each other. Suitable for testing purpose.
Use it in front of a target server and let your client programs connect it, if target server **only allows you to create
a limited TCP connections concurrently**. While it has its limitation: increased latency as incoming request will block
each other.

## arch
## Architecture

```
┌──────────┐
Expand All @@ -14,15 +15,15 @@ Use it in front of target server and let your client programs connect it, if tar
└───────────┘ └─────────────────┘ └───────────────┘
─────► tcp connection
─────► TCP connection
drawn by https://asciiflow.com/
```

Unlike reverse proxy, tcp connection between tcp-multiplexer and target server will be reused for all clients' tcp connections.

Unlike with a reverse proxy, the TCP connection between `tcp-multiplexer` and the target server will be reused for all
clients' TCP connections.

Multiplexer is simple. For every tcp connection from clients, the handling logic:
Multiplexer is simple. For every TCP connection from clients, the handling logic:

```
for {
Expand All @@ -36,31 +37,35 @@ release lock...
}
```

lock make sure that at the same time, tcp connection to target server will be used in exactly one request-response loop. That's key point for every connection from clients share one tcp connection to target server.
The lock makes sure that at any time, the TCP connection to the target server will be used in exactly one
request-response loop.
This way, all connections from clients share one TCP connection to the target server.

Next key point is how to detect message (e.g., HTTP Message format) from tcp data stream.
Next key point is how to detect message (e.g., HTTP) from the TCP data stream.

## supported application protocol
## Supported application protocols

Every application protocol (request–response message exchange pattern) has it's own message format. For now, support:
Every application protocol (request–response message exchange pattern) has its own message format. For now, support:

1. echo: \n terminated
2. http1 (not include https, websocket): not fully supported
3. iso8583: with 2 bytes header of the length of iso8583 message
4. modbus-tcp

```
$ ./tcp-multiplexer list
* iso8583
* echo
* http
* modbus
usage for example: ./tcp-multiplexer server -p echo
```

See detailed: https://github.com/XUJiahua/tcp-multiplexer/tree/master/example
See detailed: https://github.com/ingmarstein/tcp-multiplexer/tree/master/example

## usage
## Usage

```
$ ./tcp-multiplexer server -h
Expand All @@ -79,16 +84,22 @@ Global Flags:
-v, --verbose verbose log
```

### multiplexing echo server
#### In a container
```
docker run ghcr.io/ingmarstein/tcp-multiplexer server -t 127.0.0.1:1234 -l 8000 -p modbus
```
Alternatively, use the included `compose.yml` file as a template if you prefer to use Docker Compose.

### Multiplexing echo server

start echo server (listen on port 1234)
Start echo server (listen on port 1234)

```
$ go run example/echo-server/main.go
1: 127.0.0.1:1234 <-> 127.0.0.1:58088
```

start tcp multiplexing (listen on port 8000)
Start TCP multiplexing (listen on port 8000)

```
$ ./tcp-multiplexer server -p echo -t 127.0.0.1:1234 -l 8000
Expand All @@ -110,7 +121,3 @@ $ nc 127.0.0.1 8000
mmm
mmm
```




8 changes: 8 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
modbus-proxy:
image: ghcr.io/ingmarstein/tcp-multiplexer
container_name: modbus_proxy
ports:
- "5020:5020"
command: [ "server", "-t", "192.168.1.22:1502", "-l", "5020", "-p", "modbus", "-v" ]
restart: unless-stopped

0 comments on commit a084863

Please sign in to comment.