def process(self, msg, client): result = '' self.currentClient = client recvMsg = message.loads(msg) while recvMsg is not None: if recvMsg.toEnd == 'server': result = result + recvMsg.process(self).toResultString() else: recvMsg.result(self) recvMsg = message.loads('')
def process(self, msg, client): result = '' recvMsg = message.loads(msg) while recvMsg is not None: if recvMsg.toEnd == 'client': result = result + recvMsg.process(self.ui).toResultString() else: responseMsg = recvMsg.result(self.ui) if responseMsg is not None: result = result + responseMsg.toParamString() recvMsg = message.loads('')
def run(self): while True: if not self.alive: break ready = select([self.socket], [], [], 1) if ready[0]: self.buff += self.socket.recv(1024) while True: self.buff, obj = message.loads(self.buff) if obj is None: break self.callback(obj)
def parseClientMessage(self, sock, buff): self.client_info[sock].buff += buff new_buff, obj = message.loads(self.client_info[sock].buff) if obj is None: return if obj["code"] == 100: chat_msg = ChatMessage(self.client_info[sock].username, obj["message"]) self.sendAllMessage(chat_msg) elif obj["code"] == 101: old_username = self.client_info[sock].username self.client_info[sock].username = obj["username"] sock.send(message.dumps({"code": 202, "new": obj["username"]})) self.usernameChanged(old_username, self.client_info[sock].username) self.client_info[sock].buff = new_buff