From 1084f604db58d07a4fea8445d835b9690472651f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=C3=B6ffel?= Date: Fri, 7 Jun 2019 17:18:15 +0200 Subject: [PATCH 1/2] update readme --- README.md | 60 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index e8a95d7..f768d9b 100644 --- a/README.md +++ b/README.md @@ -1,57 +1,17 @@ # recws -[![Go Report Card](https://goreportcard.com/badge/github.com/mariuspass/recws)](https://goreportcard.com/report/github.com/mariuspass/recws) -[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) - Reconnecting WebSocket is a websocket client based on [gorilla/websocket](https://github.com/gorilla/websocket) that will automatically reconnect if the connection is dropped. -## Basic example +[![GoDoc](https://godoc.org/github.com/mariuspass/recws?status.svg)](https://godoc.org/github.com/mariuspass/recws) +[![Go Report Card](https://goreportcard.com/badge/github.com/mariuspass/recws)](https://goreportcard.com/report/github.com/mariuspass/recws) +[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) -```go -package main +## Installation -import ( - "context" - "github.com/mariuspass/recws" - "log" - "time" -) - -func main() { - ctx, cancel := context.WithCancel(context.Background()) - ws := recws.RecConn{} - ws.Dial("wss://echo.websocket.org", nil) - - go func() { - time.Sleep(2 * time.Second) - cancel() - }() - - for { - select { - case <-ctx.Done(): - go ws.Close() - log.Printf("Websocket closed %s", ws.GetURL()) - return - default: - if !ws.IsConnected() { - log.Printf("Websocket disconnected %s", ws.GetURL()) - continue - } - - if err := ws.WriteMessage(1, []byte("Incoming")); err != nil { - log.Printf("Error: WriteMessage %s", ws.GetURL()) - return - } - - _, message, err := ws.ReadMessage() - if err != nil { - log.Printf("Error: ReadMessage %s", ws.GetURL()) - return - } - - log.Printf("Success: %s", message) - } - } -} +```bash +go get github.com/mariuspass/recws ``` + +## License + +recws is open-source software licensed under the [MIT license](https://opensource.org/licenses/MIT). \ No newline at end of file From ccaeedddf53225685fa6932e4e4c81bb3bf43e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20L=C3=B6ffel?= Date: Fri, 7 Jun 2019 17:37:55 +0200 Subject: [PATCH 2/2] add KeepAliveTimeout --- examples/basic.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/basic.go b/examples/basic.go index ad6b5a7..a439816 100644 --- a/examples/basic.go +++ b/examples/basic.go @@ -9,7 +9,9 @@ import ( func main() { ctx, cancel := context.WithCancel(context.Background()) - ws := recws.RecConn{} + ws := recws.RecConn{ + KeepAliveTimeout: 10 * time.Second, + } ws.Dial("wss://echo.websocket.org", nil) go func() {