// 发送字节数组消息 // id:需要添加到b前发送的数据 // b:待发送的字节数组 // isSendAgain:是否是重新发送 // 返回值: // 错误对象 func (c *Client) SendByteMessage(id int, b []byte) error { idBytes := intAndBytesUtil.Int32ToBytes(int32(id), byterOrder) // 将idByte和b合并 b = append(idBytes, b...) // 获得数组的长度 contentLength := len(b) // 将长度转化为字节数组 header := intAndBytesUtil.Int32ToBytes(int32(contentLength), byterOrder) // 将头部与内容组合在一起 message := append(header, b...) // 发送消息 _, err := c.conn.Write(message) return err }
// 发送字节数组消息 // b:待发送的字节数组 func (c *Client) SendByteMessage(b []byte) { // 获得数组的长度 length := len(b) // 将长度转化为字节数组 header := intAndBytesUtil.Int32ToBytes(int32(length), BYTE_ORDER) // 将头部与内容组合在一起 message := append(header, b...) // 发送消息 c.Conn.Write(message) }
// 发送字节数组消息 // b:待发送的字节数组 func (c *Client) SendByteMessage(b []byte) { // 获得数组的长度 contentLength := len(b) // 将长度转化为字节数组 header := intAndBytesUtil.Int32ToBytes(int32(contentLength), byterOrder) // 将头部与内容组合在一起 message := append(header, b...) // 增加发送量(包括包头的长度+内容的长度) atomic.AddInt64(&totalSendSize, int64(HEADER_LENGTH+contentLength)) // 发送消息 c.conn.Write(message) }