def rcvMsg(sock): save = [] index = 0 global username while True: try: data = sock.recv(1024) if not data: break print(data.decode()) decode_data = data.decode('utf-8') if not 'role:' in decode_data and not 'is join' in decode_data and not 'is quit' in decode_data: save.append(decode_data) if username == "miner1" and len(save) == 10: f = open('chat.txt', 'a+t') f.writelines(str(save)) f.write('\n') f.close() pow = ProofOfWork.pow() index = Block.brick(pow, index) index = index + 1 for i in range(10): save.pop() except: pass
def rcvMsg(self, sock): save = [] index = 0 while True: try: data = sock.recv(1024) if not data: break print(data.decode()) decode_data = data.decode('utf-8') if not 'role:' in decode_data and not 'is join' in decode_data and not 'is quit' in decode_data: save.append(decode_data) self.interface.send_log(decode_data + "\n") if 'is join' in decode_data: splited_data: str = decode_data.split() received_user = splited_data[0][1:-1] if received_user != self.username: self.interface.receive_other_user(received_user) elif 'has joined' in decode_data: splited_data: str = decode_data.split() received_user = splited_data[0][1:-1] if received_user != self.username: self.interface.receive_other_user(received_user) elif 'is quit' in decode_data: splited_data: str = decode_data.split() received_user = splited_data[0][1:-1] if received_user != self.username: self.interface.remove_other_user(received_user) if len(save) == 10: f = open('chat.txt', 'a+t') f.writelines(str(save)) f.write('\n') f.close() pow = ProofOfWork.pow() index = Block.brick(pow, index) index = index + 1 for i in range(10): save.pop() else: pass except: pass