websocket
pingpong
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Print("upgrade:", err)
return
}
defer c.Close()
for {
mt, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
break
}
log.Printf("recv: %s", message)
err = c.WriteMessage(mt, message)
if err != nil {
log.Println("write:", err)
break
}
}
Reference:
- https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket#Syntax
- https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api
- https://yeti.co/blog/token-based-header-authentication-for-websockets-behind-nodejs/
- https://speakerdeck.com/eranyanay/going-infinite-handling-1m-websockets-connections-in-go
- https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb/
- https://github.com/gorilla/websocket/blob/master/examples/echo/server.go
- https://kubernetes.github.io/ingress-nginx/user-guide/miscellaneous/#websockets
- https://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/affinity/cookie/README.md
- https://stackoverflow.com/questions/15266702/proxying-websockets-with-tcp-load-balancer-without-sticky-sessions