示例#1
0
文件: conn.go 项目: nonempty/degdb
// Send a message on the specified connection. Consider Request.
func (c *Conn) Send(m *protocol.Message) error {
	msg, err := m.Marshal()
	if err != nil {
		return err
	}
	packet := make([]byte, len(msg)+4)
	binary.BigEndian.PutUint32(packet, uint32(len(msg)))
	copy(packet[4:], msg)
	_, err = c.Conn.Write(packet)
	return err
}
示例#2
0
文件: network.go 项目: raj347/degdb
// Send a message to the specified connection.
func (c *Conn) Send(m *protocol.Message) error {
	msg, err := m.Marshal()
	if err != nil {
		return err
	}
	packet := make([]byte, len(msg)+4)
	binary.BigEndian.PutUint32(packet, uint32(len(msg)))
	copy(packet[4:], msg)

	if _, err := c.Write(packet); err != nil {
		return err
	}
	c.server.Printf("Message: -> %s, %+v", c.PrettyID(), m.GetMessage())
	return nil
}