I've wrtten a websocket server in fiber's websocket, and the client is js websocket in browser.
Some questions regarding ping/pong:
conn.ReadJSON() will block, does that means I should use conn.SetPingHandler() to specify a handler, or just use the default handler?I added a testing ping sent from fiber websocket server to js client, if needed:
// ping
// TODO: not sure is this needed ?
// TODO: use goroutine pool ?
if needPing {
go func() {
pingTicker := time.NewTicker(pingPeriod)
defer func() {
pingTicker.Stop()
}()
time.Sleep(pingPeriod) // wait a while before start ping,
for {
select {
case <-pingTicker.C:
conn.WriteControl(websocket.PingMessage, []byte("ping"), time.Now().Add(time.Second*5))
log.Debug("ping")
}
}
}()
}
I also don't see any ping msg on client in chrome's devtools.
It's better to use for{ select } to handle both ping & normal msg I guess, but conn.ReadJSON() would block the goroutine, might need to create a channel for it? Didn't try yet.
BTW, any suggestion to the ping impl?