Exemplo n.º 1
0
func (con *Connection) transmitLoop() {
	for {
		// get next packet from the queue
		packet := <-con.Session.TXQueue

		// check if the queue still exists
		if packet == nil {
			return
		}

		// TODO: log packet id and some other stuff before sending
		log.Fine("sending packet %v", packet.PacketID())

		// convert to bytes
		buf := &bytes.Buffer{}
		packet.Write(buf)

		// now try to send it
		_, err := con.conn.Write(buf.Bytes())
		if err != nil {
			// TODO: fail
			return
		}
	}
}
Exemplo n.º 2
0
func (con *Connection) receiveLoop() {
	for {
		log.Finest("Waiting for packet..")
		packet, err := packets.ReadPacket(con.conn)
		if err != nil {
			log.Error("Failure in receive loop: %v", err)
			return
		}
		log.Fine("got packet %v", packet.PacketID())

		// put into receive queue
		con.Session.RXQueue <- packet
	}
}