Skip to content

wsconn is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped and keeps the connection alive.

License

Notifications You must be signed in to change notification settings

coinrust/wsconn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wsconn

wsconn is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped and keeps the connection alive.

Example

package main

import (
	"fmt"
	"github.com/coinrust/wsconn"
	"log"
)

func main() {
	wsURL := "wss://api.zb.live/websocket"
	ws := wsconn.NewWs(
		wsconn.WsUrlOption(wsURL),
		wsconn.WsDumpOption(true),
		wsconn.WsAutoReconnectOption(true),
		wsconn.WsMessageHandleFuncOption(func(bytes []byte) error {
			log.Printf("%v", string(bytes))
			return nil
		}),
		wsconn.WsErrorHandleFuncOption(func(err error) {
			log.Printf("%v", err)
		}),
	)
	ch := fmt.Sprintf("%v_depth", "zbqc") // zbqc_depth
	sub := map[string]string{
		"event":   "addChannel",
		"channel": ch,
	}
	ws.Subscribe(sub)

	select {}
}

About

wsconn is a websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped and keeps the connection alive.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages