qq_文er不二_acijms
2022-02-02 19:48
func WsHandle(writer http.ResponseWriter, request *http.Request) { var ( conn *websocket.Conn err error messageType int data []byte ) if conn, err = upgrader.Upgrade(writer, request, nil); err != nil { goto ERR } for { fmt.Printf("connection: %v", conn) if messageType, data, err = conn.ReadMessage(); err != nil { goto ERR } switch messageType { case websocket.TextMessage: fmt.Println(string(data)) if err = conn.WriteMessage(websocket.TextMessage, data); err != nil { goto ERR } break case websocket.BinaryMessage: break } } ERR: conn.Close() }
还没有人回答问题,可以看看其他问题
GO实现千万级WebSocket消息推送服务
21353 学习 · 56 问题
相似问题