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

Method SendMsg

znet/ws_connection.go:408–431  ·  view source on GitHub ↗

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

(msgID uint32, data []byte)

Source from the content-addressed store, hash-verified

406// SendMsg directly sends the Message data to the remote TCP client.
407// (直接将Message数据发送数据给远程的TCP客户端)
408func (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
434func (c *WsConnection) SendBuffMsg(msgID uint32, data []byte, opts ...ziface.MsgSendOption) error {

Callers

nothing calls this directly

Calls 4

NewMsgPackageFunction · 0.92
InsFunction · 0.92
PackMethod · 0.65
ErrorFMethod · 0.65

Tested by

no test coverage detected