wio

module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT

README

WIO (WebSockets Input Output)

WebSockets for everyday use.

Examples

Example of bootstrapped connection upgrade logic in context of fasthttp:

upgrader := ws.FastHTTPUpgrader{
  ReadBufferSize:  1024,
  WriteBufferSize: 1024,
  CheckOrigin:     func(r *fasthttp.RequestCtx) bool { return true },
}

hub := wio.CreateBroadHub(wio.CommonClientOptions[uint32]{
  PingInterval:  time.Second * 5,
  PongWait:      time.Second * 2,
  WriteBuffSize: 100,
  MaxReadBytes:  1024,
})

var counter atomic.Uint32

fasthttp.ListenAndServe("localhost:4000", func(ctx *fasthttp.RequestCtx) {
  err := upgrader.Upgrade(ctx, func(conn *ws.Conn) {
    clientId := counter.Load()
    terminated := hub.Subscribe(clientId, conn)

    counter.Add(1)
    <-terminated // Necessary in context of fasthttp to prevent nil pointer dereference of lost *ws.Conn. It doesn't block neither current execution of the outer fasthttp handler nor following executions of Upgrade one.
    fmt.Printf("Terminated (%v)", clientId)
  })

  if err != nil {
    fmt.Println("Failed to upgrade connection.")
  }
})

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL