Skip to content

Commit

Permalink
Clean up and prep for dev release
Browse files Browse the repository at this point in the history
  • Loading branch information
isobit committed May 9, 2017
1 parent 5363a1c commit 715f37f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 40 deletions.
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
# ws-tcp-relay
[![License MIT](https://img.shields.io/npm/l/express.svg)](http://opensource.org/licenses/MIT)

A relay between Websocket and TCP. All messages will be copied from all
Websocket connections to the target TCP server, and vice-versa.

In other words, it's [websocketd](https://github.com/joewalnes/websocketd), but for TCP connections instead of `STDIN` and `STDOUT`.

## Installation
```go get -u github.com/isobit/ws-tcp-relay```
A relay between WebSocket clients and TCP servers. Data received from
WebSocket clients is simply forwarded to the specified TCP server, and
vice-versa. In other words, it's
[websocketd](https://github.com/joewalnes/websocketd), but for TCP connections
instead of `STDIN` and `STDOUT`.

## Usage
```
Usage: ws-tcp-relay <tcpTargetAddress>
-p int
Port to listen on. (default 1337)
-port int
Port to listen on. (default 1337)
-p uint
The port to listen on (default 4223)
-port uint
The port to listen on (default 4223)
-tlscert string
TLS cert file path
TLS cert file path
-tlskey string
TLS key file path
TLS key file path
```

## WSS Support
To use secure websockets simply specify both the `tlscert` and `tlskey` flags.
### WSS Support
To use secure WebSockets simply specify both the `tlscert` and `tlskey` flags.

## Installation
```
go get -u github.com/isobit/ws-tcp-relay
```

## Building
`go build ws-tcp-relay.go`
Binaries are also available on the [release page](https://github.com/isobit/ws-tcp-relay/releases/).
8 changes: 0 additions & 8 deletions glide.lock

This file was deleted.

5 changes: 0 additions & 5 deletions glide.yaml

This file was deleted.

21 changes: 11 additions & 10 deletions ws-tcp-relay.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"fmt"
"log"
"flag"
"fmt"
"io"
"os"
"log"
"net"
"net/http"
"os"

"golang.org/x/net/websocket"
)

Expand Down Expand Up @@ -42,26 +43,26 @@ func usage() {
}

func main() {
var port int
var port uint
var certFile string
var keyFile string

flag.IntVar(&port, "p", 4223, "Port to listen on.")
flag.IntVar(&port, "port", 4223, "Port to listen on.")
flag.UintVar(&port, "p", 4223, "The port to listen on")
flag.UintVar(&port, "port", 4223, "The port to listen on")
flag.StringVar(&certFile, "tlscert", "", "TLS cert file path")
flag.StringVar(&keyFile, "tlskey", "", "TLS key file path")
flag.Usage = usage;
flag.Parse();
flag.Usage = usage
flag.Parse()

tcpAddress = flag.Arg(0)
if tcpAddress == "" {
fmt.Fprintln(os.Stderr, "no address specified")
fmt.Fprintln(os.Stderr, "No address specified")
os.Exit(1)
}

portString := fmt.Sprintf(":%d", port)

log.Printf("[INFO] starting server on port %d\n", port)
log.Printf("[INFO] Listening on %s\n", portString)

http.Handle("/", websocket.Handler(relayHandler))

Expand Down

0 comments on commit 715f37f

Please sign in to comment.