为了账号安全,请及时绑定邮箱和手机立即绑定

websocket读写消息不是线程安全问题

为什么说websocket读写消息不是线程安全,上节课讲的,因为一个http对应一个协程,这个方法绑定有一个协程的呢,为啥会不安全呢

正在回答

1 回答

在Godoc文档中有这一段

Concurrency
Connections support one concurrent reader and one concurrent writer.

Applications are responsible for ensuring that no more than one goroutine calls the write methods (NextWriter, SetWriteDeadline, WriteMessage, WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and that no more than one goroutine calls the read methods (NextReader, SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler) concurrently.

The Close and WriteControl methods can be called concurrently with all other
methods.

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

websocket读写消息不是线程安全问题

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信