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)