Пример #1
0
// send sends a packet from the given computer
// Values of senderLoss and acknowledgementLoss impact whether the packet is lost at the sender level or the receiver ACK level
func send(c *sr.Computer, senderLoss, acknowledgementLoss bool) {
	if sequenceNumber, err := c.Send(senderLoss, acknowledgementLoss); err != nil {
		log.Println("Error - ", err)
	} else {
		log.Printf("Sender sent packet with sequence number %d\n", sequenceNumber)
	}
}
Пример #2
0
// receiveHandler receives packets on the computer and passes knowledge of any ACKS to the channel
func receiveHandler(c *sr.Computer, name string, receivedACK chan int) {
	for {
		packet, err := c.Receive()

		if packet.ACK {
			receivedACK <- 1
		}

		if err != nil {
			log.Println("Error - ", err)
		} else {
			log.Printf("%s received: %v\n", name, packet)
		}
	}
}