Skip to content

Commit bf07690

Browse files
committed
Add option for using websocket binary frames instead of text frames
Fixes #2
1 parent 14b21c4 commit bf07690

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ instead of `STDIN` and `STDOUT`.
1010
## Usage
1111
```
1212
Usage: ws-tcp-relay <tcpTargetAddress>
13+
-b Use binary frames instead of text frames
14+
-binary
15+
Use binary frames instead of text frames
1316
-p uint
1417
The port to listen on (default 4223)
1518
-port uint
@@ -20,6 +23,10 @@ Usage: ws-tcp-relay <tcpTargetAddress>
2023
TLS key file path
2124
```
2225

26+
### Binary Data
27+
By default, `golang.org/x/net/websocket` uses text frames to deliver payload
28+
data. To use binary frames instead, use either the `b` or `binary` flags.
29+
2330
### WSS Support
2431
To use secure WebSockets simply specify both the `tlscert` and `tlskey` flags.
2532

ws-tcp-relay.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
var tcpAddress string
16+
var binaryMode bool
1617

1718
func copyWorker(dst io.Writer, src io.Reader, doneCh chan<- bool) {
1819
io.Copy(dst, src)
@@ -26,6 +27,10 @@ func relayHandler(ws *websocket.Conn) {
2627
return
2728
}
2829

30+
if binaryMode {
31+
ws.PayloadType = websocket.BinaryFrame
32+
}
33+
2934
doneCh := make(chan bool)
3035

3136
go copyWorker(conn, ws, doneCh)
@@ -51,6 +56,8 @@ func main() {
5156
flag.UintVar(&port, "port", 4223, "The port to listen on")
5257
flag.StringVar(&certFile, "tlscert", "", "TLS cert file path")
5358
flag.StringVar(&keyFile, "tlskey", "", "TLS key file path")
59+
flag.BoolVar(&binaryMode, "b", false, "Use binary frames instead of text frames")
60+
flag.BoolVar(&binaryMode, "binary", false, "Use binary frames instead of text frames")
5461
flag.Usage = usage
5562
flag.Parse()
5663

0 commit comments

Comments
 (0)