def readPacket(self): try: header = self.tcp.recv(1) ID = self.tcp.recv(1) length = self.tcp.recv(2) print self.ord(header) print self.ord(ID) except: #no data return [0,0,0] try: intlength = self.ord(length[0]) + self.ord(length[1]) data = self.tcp.recv(intlength) decompressed_data = self.zlib.decompress(data) return [header,ID,decompresseed_data] except: return [0,0,0] #It prints out 48 then 65 when it should be the other way #around.. for some reason the ID and the header are flipped. #here is the function that assembles the packet and sends it #called from the server #packet = libpac.newPacket(libpac.PAC_AUTH_LOGINGOOD,0,str(result[1]) + str(result[2]) ) #here is the code for newPacket def newPacket (header, ID,data): compressed_data = zlib.compress(data) compressed_header = chr(header) compressed_id = chr(ID) if len(compressed_data) > 255: length1 = chr(255) legth2 = chr(len(compressed_data) - 255) else: length1 = chr(len(compressed_data)) length2 = chr(0) packet = compressed_header + compressed_id + length1 + length2 + compressed_data return packet