// Receive receives a packet from a given connection
Receive receives a packet from a given connection
// Receive receives a packet from a given connection
func (c *Connection) Receive() (*Packet, error) {
	packet := &Packet{}
	packetBytes := make([]byte, maxBufferSize)
	err := c.Conn.SetReadDeadline(time.Now().Add(time.Duration(readDeadline) * time.Second))
	if err != nil {
		return nil, fmt.Errorf("error while setting read deadline: %s", err)
	}
	n, err := c.Conn.Read(packetBytes)
	if err != nil {
		if err == io.EOF {
			return nil, err
		}
		return nil, fmt.Errorf("error while reading from socket: %s", err)
	}
	if n > maxBufferSize {
		return nil, fmt.Errorf("error while reading from socket: message size too large")
	}
	err = protobuf.Decode(packetBytes[:n], packet)
	if err != nil {
		return nil, fmt.Errorf("error while deserializing packet received: %s", err)
	}
	return packet, nil
}
func ( c * Connection ) Receive ( ) ( * Packet , error ) { packet := & Packet { } packetBytes := make ( [ ] byte , maxBufferSize ) err := c . Conn . SetReadDeadline ( time . Now ( ) . Add ( time . Duration ( readDeadline ) * time . Second ) ) if err != nil { return nil , fmt . Errorf ( " " , err ) } n , err := c . Conn . Read ( packetBytes ) if err != nil { if err == io . EOF { return nil , err } return nil , fmt . Errorf ( " " , err ) } if n > maxBufferSize { return nil , fmt . Errorf ( " " ) } err = protobuf . Decode ( packetBytes [ : n ] , packet ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return packet , nil }
Receive receives a packet from a given connection
Receive receives a packet from a given connection
// decode message