You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-20Lines changed: 27 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,10 @@
1
-
2
1
# tcp-multiplexer
3
2
4
-
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.
3
+
Use it in front of a target server and let your client programs connect it, if target server **only allows you to create
4
+
a limited TCP connections concurrently**. While it has its limitation: increased latency as incoming request will block
5
+
each other.
5
6
6
-
## arch
7
+
## Architecture
7
8
8
9
```
9
10
┌──────────┐
@@ -14,15 +15,15 @@ Use it in front of target server and let your client programs connect it, if tar
Unlike reverse proxy, tcp connection between tcp-multiplexer and target server will be reused for all clients' tcp connections.
23
-
23
+
Unlike with a reverse proxy, the TCP connection between `tcp-multiplexer` and the target server will be reused for all
24
+
clients' TCP connections.
24
25
25
-
Multiplexer is simple. For every tcp connection from clients, the handling logic:
26
+
Multiplexer is simple. For every TCP connection from clients, the handling logic:
26
27
27
28
```
28
29
for {
@@ -36,31 +37,35 @@ release lock...
36
37
}
37
38
```
38
39
39
-
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.
40
+
The lock makes sure that at any time, the TCP connection to the target server will be used in exactly one
41
+
request-response loop.
42
+
This way, all connections from clients share one TCP connection to the target server.
40
43
41
-
Next key point is how to detect message (e.g., HTTP Message format) from tcp data stream.
44
+
Next key point is how to detect message (e.g., HTTP) from the TCP data stream.
42
45
43
-
## supported application protocol
46
+
## Supported application protocols
44
47
45
-
Every application protocol (request–response message exchange pattern) has it's own message format. For now, support:
48
+
Every application protocol (request–response message exchange pattern) has its own message format. For now, support:
46
49
47
50
1. echo: \n terminated
48
51
2. http1 (not include https, websocket): not fully supported
49
52
3. iso8583: with 2 bytes header of the length of iso8583 message
53
+
4. modbus-tcp
50
54
51
55
```
52
56
$ ./tcp-multiplexer list
53
57
* iso8583
54
58
* echo
55
59
* http
60
+
* modbus
56
61
57
62
usage for example: ./tcp-multiplexer server -p echo
58
63
59
64
```
60
65
61
-
See detailed: https://github.com/XUJiahua/tcp-multiplexer/tree/master/example
66
+
See detailed: https://github.com/ingmarstein/tcp-multiplexer/tree/master/example
62
67
63
-
## usage
68
+
## Usage
64
69
65
70
```
66
71
$ ./tcp-multiplexer server -h
@@ -79,16 +84,22 @@ Global Flags:
79
84
-v, --verbose verbose log
80
85
```
81
86
82
-
### multiplexing echo server
87
+
#### In a container
88
+
```
89
+
docker run ghcr.io/ingmarstein/tcp-multiplexer server -t 127.0.0.1:1234 -l 8000 -p modbus
90
+
```
91
+
Alternatively, use the included `compose.yml` file as a template if you prefer to use Docker Compose.
92
+
93
+
### Multiplexing echo server
83
94
84
-
start echo server (listen on port 1234)
95
+
Start echo server (listen on port 1234)
85
96
86
97
```
87
98
$ go run example/echo-server/main.go
88
99
1: 127.0.0.1:1234 <-> 127.0.0.1:58088
89
100
```
90
101
91
-
start tcp multiplexing (listen on port 8000)
102
+
Start TCP multiplexing (listen on port 8000)
92
103
93
104
```
94
105
$ ./tcp-multiplexer server -p echo -t 127.0.0.1:1234 -l 8000
0 commit comments