def subscribe(self, func, params): self.seq += 1 d = {u"func": func, u"params": params} sendPack = TTPackage(self.seq, NET_CMD_RPC, d) datas = sendPack.encode() self.socket.sendall(datas) return self.seq
def _recvOnePackage(self): strLen = self._recv_all(4) packLen, = struct.unpack_from("!I", strLen, 0) strContent = self._recv_all(packLen - 4) datas = strLen + strContent package = TTPackage() package.decode(datas) return package
def request(self, func, params): self.seq += 1 d = {u"func": func, u"params": params} sendPack = TTPackage(self.seq, NET_CMD_RPC, d) datas = sendPack.encode() self.socket.sendall(datas) while True: recvPack = self._recvOnePackage() if recvPack.seq == self.seq: if recvPack.data["status"] == 0: return recvPack.data[u"params"] else: raise Exception(recvPack.data[u"params"]) else: if self.handler: self.handler.handle_sub_pack(recvPack.data[u"params"])
def request(self, func, params): self.seq += 1 d = {u"func": func, u"params": params} sendPack = TTPackage(self.seq, NET_CMD_RPC, d) datas = sendPack.encode() self.socket.sendall(datas) while True: recvPack = self._recvOnePackage() if recvPack.seq == self.seq: if recvPack.data["status"] == [0] or recvPack.data["status"] == 0: return recvPack.data[u"params"] else: raise Exception(recvPack.data[u"params"]) else: if self.handler: self.handler.handle_sub_pack(recvPack.data[u"params"])