SendMsg directly sends Message data to the remote KCP client. (直接将Message数据发送数据给远程的KCP客户端)
(msgID uint32, data []byte)
| 409 | // SendMsg directly sends Message data to the remote KCP client. |
| 410 | // (直接将Message数据发送数据给远程的KCP客户端) |
| 411 | func (c *KcpConnection) SendMsg(msgID uint32, data []byte) error { |
| 412 | if c.isClosed() { |
| 413 | return errors.New("connection closed when send msg") |
| 414 | } |
| 415 | // Pack data and send it |
| 416 | msg, err := c.packet.Pack(zpack.NewMsgPackage(msgID, data)) |
| 417 | if err != nil { |
| 418 | zlog.Ins().ErrorF("Pack error msg ID = %d", msgID) |
| 419 | return errors.New("Pack error msg ") |
| 420 | } |
| 421 | |
| 422 | err = c.Send(msg) |
| 423 | if err != nil { |
| 424 | zlog.Ins().ErrorF("SendMsg err msg ID = %d, data = %+v, err = %+v", msgID, string(msg), err) |
| 425 | return err |
| 426 | } |
| 427 | |
| 428 | return nil |
| 429 | } |
| 430 | |
| 431 | func (c *KcpConnection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error { |
| 432 | if c.isClosed() { |