示例#1
0
func (s *Server) handlePacket(p packet.Packet, c *client.Client) {
	switch p.PacketType() {
	case packet.REQUEST:
		//send details packet
	case packet.ACK:
		//start streaming
	case packet.CLOSE:
		s.CloseConn(c)
	case packet.PING:
		s.SendPacket(packet.NewPongPacket(0), c)
	case packet.PONG:
		//do nothing, client keep alive
	default:
		logger.Printf("Invalid packet with type: %d", p.PacketType())
	}
}
示例#2
0
func (c *Client) handlePacket(p packet.Packet) {
	switch p.PacketType() {
	case packet.DETAILS:
		//handle stream details
	case packet.STREAM:
		//handle streaming
	case packet.CLOSE:
		//close client
	case packet.PING:
		c.SendPacket(packet.NewPongPacket(0))
	case packet.PONG:
		//handle server last seen time
	default:
		logger.Printf("Invalid packet type: %d", p.PacketType())
	}
}
示例#3
0
func (*Server) SendPacket(p packet.Packet, c *client.Client) error {
	_, err := c.Conn.Write(p.Raw())
	return err
}
示例#4
0
func (c *Client) SendPacket(p packet.Packet) error {
	_, err := c.Conn.Write(p.Raw())
	return err
}