Exemple #1
0
 def send(self, data):
     scr = RDLaser.checksum(RDLaser.scramblestr(data))
     if self.debug:
         print u"\x1B[42m> " + self.addr + ": " + (
             scr.encode("hex")) + u"\x1B[0m  -  " + data.encode("HEX")
     RDLaser.getClient().sendto(scr, (self.addr, RDLaser.SERVER_PORT))
     data, server_addr = self.recv()
     if (data != '\xc6'):
         return False
     return True
 def recv(self):
     data, addr = RDLaser.getServer().recvfrom(RDLaser.BUF_SIZE)
     if data[:2] != RDLaser.checksum(data[2:])[:2]:
         print data[0:2].encode("HEX")
         if self.debug:
             print(u"\x1B[31mCHECKSUM MISMATCH\x1B[0m")
         return ("", addr)
     data = RDLaser.descramblestr(data[2:])
     if self.debug:
         print(u"\x1B[34m< " + addr[0] + ": " +
               RDLaser.scramblestr(data).encode("HEX") + u"\x1B[0m  -  " +
               data.encode("HEX"))
     self.send(addr[0], '\xcc')  #send ACK
     return (data, addr)