modulepackage
1.1.0
Repository: https://github.com/dnsge/go-basic-websocket.git
Documentation: pkg.go.dev
# README
go-basic-websocket
Simple WebSocket client
Example program using https://www.websocket.org/echo.html:
package main
import (
"fmt"
"github.com/dnsge/go-basic-websocket"
"net/http"
"sync"
"time"
)
func main() {
// simple echo websocket
headers := http.Header{
"User-Agent": []string{"echo-client/1.0"},
}
ws := basicws.NewBasicWebsocket("wss://echo.websocket.org", headers)
wg := sync.WaitGroup{}
ws.OnConnect = func() {
fmt.Println("Connected to server!")
time.AfterFunc(time.Second*3, func() {
ws.SendString("Hello, world!")
})
}
ws.OnMessage = func(b []byte) error {
fmt.Printf("Received message: %s\n", string(b))
ws.Disconnect()
wg.Done()
return nil
}
wg.Add(1)
_ = ws.Connect()
wg.Wait()
}
Output:
Connected to server!
Received message: Hello, world!
# Functions
Create a new BasicWebsocket with a URL and Header.
# Variables
No description provided by the author
# Structs
No description provided by the author