Esempio n. 1
0
 def __ListenForMessages(self):
     """
     This method will be ran in a separate thread as the main/ui thread, because the for-in call is blocking
     when waiting for new messages
     """
     for note in self.conn.ChatStream(chat.Empty()):
         print("R[{}] {}".format(note.name, note.message))
Esempio n. 2
0
 def __listen_for_messages(self):
     """
     This method will be ran in a separate thread as the main/ui thread, because the for-in call is blocking
     when waiting for new messages
     """
     for note in self.conn.ChatStream(chat.Empty(
     )):  # this line will wait for new messages from the server!
         print("R[{}] {}".format(note.name,
                                 note.message))  # debugging statement
         self.chat_list.insert(END, "[{}] {}\n".format(
             note.name, note.message))  # add the message to the UI
Esempio n. 3
0
    def SendNote(self, request: chat.Note, context):
        """
        This method is called when a clients sends a Note to the server.

        :param request:
        :param context:
        :return:
        """
        print("[{}] {}".format(request.name, request.message))
        # Add it to the chat history
        self.chats.append(request)
        gConn[request.name] = context
        return chat.Empty()
Esempio n. 4
0
    def _listen_for_messages(self):
        if not self._stub:
            return

        try:
            # The cycle will wait until the messages come, process all those who have come and wait for the next
            for note in self._stub.ChatStream(chat.Empty()):
                if self.stop_working:
                    break
                self._on_message_receive(note)
        except:
            if self.on_server_unavailable:
                self.on_server_unavailable()
Esempio n. 5
0
 def SendNote(self, request: chat.Note, context):
     """
     This method is called when a clients sends a Note to the server.
     :param request:
     :param context:
     :return:
     """
     # this is only for the server console
     print("[{}] {}".format(request.name, request.message))
     # Add it to the chat history
     self.chats.append(request)
     return chat.Empty(
     )  # something needs to be returned required by protobuf language, we just return empty msg
Esempio n. 6
0
 def SendText(self, request: chat.Text, context):
     print("SendText: {} {}".format(request.name, request.msg))
     self.chat_messages.append(request)
     return chat.Empty()
Esempio n. 7
0
 def SendNote(self, request, context):
     self.chat_history.append(request)
     return chat_pb2.Empty()
Esempio n. 8
0
 def __listen_for_messages(self):
     for text in self.conn.ChatStream(chat.Empty()):
         print("Receive: [{}] {}".format(text.name, text.msg))
         self.chats.insert(
             END, "({}) [{}]: {}\n".format(text.timestamp, text.name,
                                           text.msg))