0

I am trying to send a list of active users on my chatting app and add them to a tkinter listbox on each client, if they disconnect send an updated list to then remove the offline users from the listbox. Here is my client side:

        while True:
            message = b''
            while True:
                message = sock_chat.recv(BUFFER)
                users = pickle.loads(message)
                print(users)
                if ":" in users:
                    """ 
                    Load the message from server and put in chatlog
                    """
                    self.app.chatlog.config(state=NORMAL)
                    self.app.chatlog.insert(INSERT, (users))
                    self.app.chatlog.insert(INSERT, "\n")
                    self.app.chatlog.config(state=DISABLED)
                    self.app.chatlog.see("end")
                    message = b''
                else:
                    """ 
                    Load the connection information and put them on friend list
                    """
                    self.app.friends.append(users)
                    message = b''    
                    print (self.app.friends)

here is my server:

def broadcast(message, flag = False):
    if flag == True:
        users = pickle.dumps(online)
        for client2 in clients:
            client2.send(users)
    else:
        pick = pickle.dumps(message)
        for client2 in clients:
            client2.send(pick)

1 Answers1

0

I know that's not the same example as it uses Flask, but the issue is definitely the same. You better think on using WebSockets for such kind of WebServer, here is the answer: Emit websocket message from a view

Izuki13
  • 54
  • 6