class packet: def __init__(self, type, format, size): self.type = type self.format = format self.size = size #ADD TO DICT OF PACKETS PACKETDICT[type] = self def __str__(self): return self.type def execute(self,data): print data class RequestLogin(packet): def __init__(self): packet.__init__(self,"L","s","*") def pack(self,data): type = pack("c",self.type) size = pack("i", len(data) )#override size data = pack( str(len(data)) + self.format, data) packet = type + size + data return packet class SendLoginInfo(packet): def __init__(self): packet.__init__(self, "l", "i", 4) def pack(self,data): type = pack("c",self.type) size = pack("i",self.size) data = pack(self.format, data) packet = type + data return packet pRequestLogin = RequestLogin() pSendLoginInfo = SendLoginInfo()