Exemple #1
0
 def send_packet(self, packet):
     packet.checksum = RxPacket.calculate_checksum(packet)
     self.logger.debug("Sending packet to %s at port %s: " % (packet.destinationip, packet.destport))
     # set the packet send time
     packet.sent_time = time.time()
     # if the packet needs to be acked then it has to be added to the waiting to be acked list
     if any(flag in [RxPFlags.SYN, RxPFlags.FIN, RxPFlags.DATA] for flag in packet.flags):
         self.waiting_to_be_acked[packet.sequence] = packet
         # if the RETRY Thread is not running, kick it off
         if not self.RETRY_THREAD:
             t = Timer(self.RETRY_DELAY, self.resend_unacked_packets)
             t.setDaemon(True)
             t.start()
             self.RETRY_THREAD = True
     # Send packet over UDP
     self.sock.sendto(RxPacket.serialize(packet), (packet.destinationip, packet.destport))
     self.logger.debug("Sent Packet, returning to calling function")
 def test_receive_packet(self):
     test_packet = TestPacket([RxPFlags.DATA], 10, data=bytearray("Hello", 'utf-8'))
     test_packet.checksum = RxPacket.calculate_checksum(test_packet)
     self.communicator.sock.test_packet = RxPacket.serialize(test_packet)
     self.assertIsNotNone(self.communicator.receive_packet())