Reconnecting WebSocket is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped - thread safe!
- Automatic reconnection with configurable backoff
- Thread-safe operations
- Structured logging with configurable levels
- Robust keepalive mechanism
- Proper connection establishment with channel-based synchronization
- TLS support
- Proxy support
- Compression support (RFC 7692)
- Graceful shutdown support
go get github.com/inference-sh/recws
import "github.com/inference-sh/recws"
// Create a new reconnecting websocket
ws := &recws.RecConn{
KeepAliveTimeout: 30 * time.Second,
}
// Connect (blocks until connection is established or timeout reached)
ws.Dial("ws://example.com/ws", nil)
// Send/receive messages
ws.WriteMessage(websocket.TextMessage, []byte("hello"))
See the examples directory for complete working examples.
This library is designed to be used as a WebSocket client (the connecting end) that initiates connections to a WebSocket server. It is not meant to be used for implementing WebSocket server endpoints. If you're looking to implement a WebSocket server, please use the gorilla/websocket
package directly instead.
See the examples directory for complete working examples.
This library is designed to be used as a WebSocket client (the connecting end) that initiates connections to a WebSocket server. It is not meant to be used for implementing WebSocket server endpoints. If you're looking to implement a WebSocket server, please use the gorilla/websocket
package directly instead.
- Logo by Anastasia Marx
- Gopher by Gophers
recws is open-source software licensed under the MIT license.