def __listen_for_messages(self):
     print("Listen")
     for i in range(trys):
         try:
             for note in self.conn.ReceiveMessage(
                     chat.First(roomname=self.Roomname,
                                nickname=self.Nickname)):
                 self.chats.append(note)
             break
         except Exception as e:
             print("Receive")
             print(e)
             self.new_channel()
    def ReceiveMessage(self, request, context):
        print("Send it all")
        resp_node = self.server.FindResponsible(request, context)
        room_name = request.roomname
        resp_serv = resp_node[1][1]

        if not resp_node[
                0]:  # Communicate with the server that might know who will respond the request
            for serv in resp_serv:
                try:
                    channel = grpc.insecure_channel(self.server.address + ':' +
                                                    str(serv))
                    conn = rpc.ChatSServerStub(
                        channel)  ## connection with the responsible server
                    result = conn.FindResponsible(
                        chat.FindRRequest(roomname=room_name))
                    resp_serv = self.Str_to_list_ports(result.port)
                except:
                    print("False Fai Receive Message at", serv)

        if self.Request_port() in resp_serv:
            lastindex = 0
            aux = None
            while not aux:
                aux = self.server.Validade_User(request.roomname,
                                                request.nickname)
            if aux != None:
                while True:
                    while lastindex < len(aux.Chats):
                        n = aux.Chats[lastindex]
                        n = chat.Note(roomname=request.roomname,
                                      nickname=n['nickname'],
                                      message=n['message'])
                        lastindex += 1
                        yield n
        print("What")
        for serv in resp_serv:
            try:
                channel = grpc.insecure_channel(self.server.address + ':' +
                                                str(serv))
                conn = rpc.ChatSServerStub(
                    channel)  ## connection with the server
                for note in conn.ReceiveMessage(
                        chat.First(roomname=request.roomname,
                                   nickname=request.nickname)):
                    yield note
                break
            except:
                print("Error Receive Message at", serv)