Beispiel #1
0
clientsConnectes=[]

while serveurLance :
    connecDemandees,wlist,xlist = select.select([connecMain],[],[],0.05)
    for connexion in connecDemandees:
        connecClient, infosConnec = connexion.accept()
        clientsConnectes.append(connecClient)
    clientsALire = []
    try:
        clientsALire,wlist,xlist = select.select(clientsConnectes,[],[],0.05)
    except select.error:
        pass
    else:
        for client in clientsALire:
            msgRecu = client.recv(1024)
            msgRecu2 = protocols.recevoir(msgRecu)
            print("recu : {}".format(msgRecu2))
            for clients in clientsConnectes :
                if clients != client:
                    clients.send(msgRecu)
            if msgRecu2["msg"] == "/affiche":
                #print("/affiche")

                msgEnvoi=protocols.envoyer("client","all","001","5/5")
                client.send(msgEnvoi)
            elif msgRecu2["msg"] == "/quit":
                client.close()
print("fermeture connexion")
for client in clientsConnectes:
    client.close()
Beispiel #2
0
def ecoute():
    while 1:
        msgRecu = connecServeur.recv(1024)
        msgRecu2 = protocols.recevoir(msgRecu)["msg"]
        print(msgRecu2)