所以我一直在开发一个聊天室客户端,除了我有一个问题。我一直希望能够列出谁在线,最简单的方法是使用变量。我将有一个起始变量,例如:
在线客户 = []
当其他客户加入时,我希望他们的客户发送变量“OnlineClients.append(name)”以将其添加到列表中。当他们退出时,它还应该发送命令“OnlineClients.remove(name)”。有什么办法可以做到这一点吗?
这是我尝试发送变量的代码片段:
#This list is important because it is used for listing who is on the chat
OnlineClients = ["Person1", "Person2", "Person3"]
ListOnline = (" ".join(OnlineClients))
#THIS IS TEST 1 FOR VARIABLE SENDING
#In future update remove own name from online list
#!to_varlist = (OnlineClients.append(name))
s.send(OnlineClients.append("Apple").encode())
#to_send = (person1 = name)
#s.send(to_send.encode())
#to_var = a = b
#s.send(to_var.encode())
#s.send(a=b.encode())