MCPcopy
hub / github.com/aceld/zinx / SendMsg

Method SendMsg

znet/kcp_connection.go:411–429  ·  view source on GitHub ↗

SendMsg directly sends Message data to the remote KCP client. (直接将Message数据发送数据给远程的KCP客户端)

(msgID uint32, data []byte)

Source from the content-addressed store, hash-verified

409// SendMsg directly sends Message data to the remote KCP client.
410// (直接将Message数据发送数据给远程的KCP客户端)
411func (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
431func (c *KcpConnection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error {
432 if c.isClosed() {

Callers

nothing calls this directly

Calls 6

isClosedMethod · 0.95
SendMethod · 0.95
NewMsgPackageFunction · 0.92
InsFunction · 0.92
PackMethod · 0.65
ErrorFMethod · 0.65

Tested by

no test coverage detected