def template_SerializeAndDeserialize(self, seq, ack, ackbits, payload):
     d = UDPDatagram()
     d.seq = seq
     d.ack = ack
     d.ackbits = ackbits
     d.payload = payload
     b = d.Serialize()
     e = UDPDatagram()
     e.Deserialize(b)
     self.assertTrue(d == e)
Beispiel #2
0
 def Send(self, payload):
     '''
     Argument:
     payload-- The data to send.
     Return value:
     True if this method succeeded.
     '''
     assert len(payload) <= UDPDatagram.MAX_PAYLOAD
     datagram = UDPDatagram()
     datagram.seq = self.seq
     datagram.ack = self.ack
     datagram.ackbits = self.ackbits
     datagram.payload = payload
     buf = datagram.Serialize()
     self.sock.send(buf)
     self.seq = (self.seq + 1) % UDPDatagram.MAX_SEQ
     self.ttl -= 1
     if self.ttl <= 0:
         logger.info('The connection is dead.')
         return False
     return True