SendMsg directly sends the Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)
(msgID uint32, data []byte)
| 406 | // SendMsg directly sends the Message data to the remote TCP client. |
| 407 | // (直接将Message数据发送数据给远程的TCP客户端) |
| 408 | func (c *WsConnection) SendMsg(msgID uint32, data []byte) error { |
| 409 | c.msgLock.Lock() |
| 410 | defer c.msgLock.Unlock() |
| 411 | if c.isClosed == true { |
| 412 | return errors.New("WsConnection closed when send msg") |
| 413 | } |
| 414 | |
| 415 | // Package data and send |
| 416 | // (将data封包,并且发送) |
| 417 | msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data)) |
| 418 | if err != nil { |
| 419 | zlog.Ins().ErrorF("Pack error msg ID = %d", msgID) |
| 420 | return errors.New("Pack error msg ") |
| 421 | } |
| 422 | |
| 423 | // Write back to the client |
| 424 | err = c.conn.WriteMessage(websocket.BinaryMessage, msg) |
| 425 | if err != nil { |
| 426 | zlog.Ins().ErrorF("SendMsg err msg ID = %d, data = %+v, err = %+v", msgID, string(msg), err) |
| 427 | return err |
| 428 | } |
| 429 | |
| 430 | return nil |
| 431 | } |
| 432 | |
| 433 | // SendBuffMsg sends BuffMsg |
| 434 | func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error { |
nothing calls this directly
no test coverage detected