StartWriter is a Goroutine that sends messages to the client (StartWriter 写消息Goroutine, 用户将数据发送给客户端)
()
| 183 | // StartWriter is a Goroutine that sends messages to the client |
| 184 | // (StartWriter 写消息Goroutine, 用户将数据发送给客户端) |
| 185 | func (c *WsConnection) StartWriter() { |
| 186 | zlog.Ins().InfoF("Writer Goroutine is running") |
| 187 | defer zlog.Ins().InfoF("%s [conn Writer exit!]", c.RemoteAddr().String()) |
| 188 | |
| 189 | for { |
| 190 | select { |
| 191 | case data, ok := <-c.msgBuffChan: |
| 192 | if ok { |
| 193 | if err := c.Send(data); err != nil { |
| 194 | zlog.Ins().ErrorF("Send Buff Data error:, %s Conn Writer exit", err) |
| 195 | break |
| 196 | } |
| 197 | |
| 198 | } else { |
| 199 | zlog.Ins().ErrorF("msgBuffChan is Closed") |
| 200 | break |
| 201 | } |
| 202 | case <-c.ctx.Done(): |
| 203 | return |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // StartReader is a Goroutine that reads messages from the client. |
| 209 | // (StartReader 读消息Goroutine,用于从客户端中读取数据) |