使用github.com/gorilla/websocket 创建websocket接口,客户端并发调用,但是返回concurrent write to websocket connection
有疑问加站长微信联系(非本文作者)

使用github.com/gorilla/websocket 创建websocket接口,客户端并发调用,但是返回concurrent write to websocket connection
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
`单行代码`
这个问题也困扰了我 今天解决了
根本问题在于这个库 不支持并发写同一个conn 官方描述如下
Connections support one concurrent reader and one concurrent writer. Applications are responsible for ensuring that no more than one goroutine calls the write methods
所以我的解决是 定义 type xxx struct { con *websocket.Conn mutex sync.Mutex } 在原来直接操作con的地方 传入这个结构体 判断锁