def JoinChat(self, request, context): 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 Fail Join Chat at", serv) if self.Request_port() in resp_serv: return self.server.JoinChat(request, context) for serv in resp_serv: try: channel = grpc.insecure_channel(self.server.address + ':' + str(serv)) conn = rpc.ChatSServerStub(channel) return conn.JoinChat( chat.JoinChatRequest(roomname=request.roomname, password=request.password, nickname=request.nickname)) break except: print("True Fail Join Chat at", serv) print("What do i do ?")
def Join_to_chatRoom(self, Roomname, Password, Nickname): for i in range(trys): try: response = self.conn.JoinChat( chat.JoinChatRequest(roomname=Roomname, password=Password, nickname=Nickname)) break except: self.new_channel() print(response.state) if response.state == 'sucess': self.Nickname = Nickname self.Roomname = Roomname self.chats.clear( ) ## remove any old chat that could be in the chat list self.start_Listenner() return True else: return False