SendMsg directly sends Message data to the remote TCP client. (直接将Message数据发送数据给远程的TCP客户端)
(msgID uint32, data []byte)
| 445 | // SendMsg directly sends Message data to the remote TCP client. |
| 446 | // (直接将Message数据发送数据给远程的TCP客户端) |
| 447 | func (c *Connection) SendMsg(msgID uint32, data []byte) error { |
| 448 | |
| 449 | if c.isClosed() == true { |
| 450 | return errors.New("connection closed when send msg") |
| 451 | } |
| 452 | // Pack data and send it |
| 453 | msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data)) |
| 454 | if err != nil { |
| 455 | zlog.Ins().ErrorF("Pack error msg ID = %d", msgID) |
| 456 | return errors.New("Pack error msg ") |
| 457 | } |
| 458 | |
| 459 | err = c.Send(msg) |
| 460 | if err != nil { |
| 461 | zlog.Ins().ErrorF("SendMsg err msg ID = %d, data = %+v, err = %+v", msgID, string(msg), err) |
| 462 | return err |
| 463 | } |
| 464 | |
| 465 | return nil |
| 466 | } |
| 467 | |
| 468 | func (c *Connection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error { |
| 469 | msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data)) |