Пример #1
0
func (c *client) send(p packet.Packet) error {
	b, err := p.Encode()
	if err != nil {
		return err
	}
	if c.pf == nil {
		// send without PacketFilter
		_, err = c.conn.Write(b)
		if err != nil {
			return err
		}
		return nil
	}
	// send with PacketFilter
	b2, err := c.pf.PreSend(p, b)
	if err != nil {
		return err
	}
	_, err = c.conn.Write(b2)
	if err != nil {
		return err
	}
	c.pf.PostSend(p, b2)
	return nil
}
Пример #2
0
func (c *client) send(p packet.Packet) error {
	c.sl.Lock()
	defer c.sl.Unlock()
	if c.conn == nil {
		return errors.New("connection closed")
	}
	b, err := p.Encode()
	if err != nil {
		return err
	}
	err = c.sendRaw(b)
	if err != nil {
		return err
	}
	c.keepAliveExtend()
	return nil
}