Bonjours j'ai réaliser un programme qui permet au client de connaitre rapidement l'etat d'un reseau http://www.developpez.net/forums/d15...-notification/. Le soucis c'est que le serveur doit tenir informer plusieur dizaine de clients or 1client RAS, 2clients sa va, 3clients ça lag (interface serveur), 4clients le serveur freeze; on est loin de la dizaine je voudrais donc savoir comment résoudre ce soucis. (ce n'est pas le Pc j'ai un i7-4790k avec 16Go de ram).
J'ai penser a reduire le nombre de thread mais je ne voie pas par quoi les remplacers, je me suis dit que ça pouvait venir des "while True" ?

Serveur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import socket
import threading
from tkinter import *
 
global Client_online, Etat_reseau
 
 
def Etat_0():
    Etat_reseau.set("Bon")
    print("Update", Etat_reseau.get())
 
def Etat_1():
    Etat_reseau.set("Moyen")
    print("Update", Etat_reseau.get())
 
def Etat_2():
    Etat_reseau.set("Mauvais")
    print("Update", Etat_reseau.get())
 
 
class ClientThread(threading.Thread):
 
    def __init__(self, ip, port, clientsocket, Etat_reseau):
 
        threading.Thread.__init__(self)
        self.ip = ip
        self.port = port
        self.clientsocket = clientsocket
        self.Etat_reseau_client = StringVar()
        self.Etat_reseau_client.set("none")
        self.Etat_reseau = Etat_reseau.get()
 
        print("[+] Nouveau thread pour %s %s" % (self.ip, self.port, ))
 
        Client_online.append(ip)
 
    def run(self):
 
        nb_send = 0
        paquet = ""
 
        #print("Etat_reseau_client ",self.Etat_reseau_client)
 
        print("ConnecTion de %s %s" % (self.ip, self.port, ))
        print("HH", Etat_reseau.get(), self.Etat_reseau_client.get())
 
 
        while True: #Envoie l'etat seulement lors d'une update ou du premier cycle(le client ne connais pas l'etat)
 
            #print("tt", Etat_reseau.get(), self.Etat_reseau_client.get())
 
            if Etat_reseau.get() != self.Etat_reseau_client.get() or nb_send == 0:
 
                nb_send = nb_send + 1
 
                #print('ici')
 
                a = Etat_reseau.get()
                self.Etat_reseau_client.set(a)
                paquet = str(str(self.Etat_reseau_client.get()) + chr(0)).encode('latin-1')
                self.clientsocket.send(paquet)
 
                print("nb_send", nb_send, "ET", Etat_reseau.get(), "ETC", self.Etat_reseau_client.get())
 
 
 
 
class Ecoute(threading.Thread): #Thread d'ecoute qui permet au client de ce connecter
 
    def __init__(self, ip, port, clientsocket, Etat_reseau):
 
        threading.Thread.__init__(self)
 
    def run(self):
 
        while True:
            tcpsock.listen(1000)#Nb de client pouvant etre connecter au serveur
            print( " En écoute...")
            (clientsocket, (ip, port)) = tcpsock.accept()
            newthread = ClientThread(ip, port, clientsocket, Etat_reseau)
            newthread.start()
 
 
 
Client_online = []
ip = ""
port = 0
clientsocket = ""
 
 
 
fenetre_choix = Tk()
fenetre_choix.title("Panel d'administration")
fenetre_choix.configure(bg = "#00B3D7")
 
button_heber = Button(fenetre_choix, text = "Aucun probleme connue",font="arial 12 bold",command=Etat_0, bg = "white", relief=FLAT)
button_rej = Button(fenetre_choix, text = "Perturbation connue sur le reseau",font="arial 12 bold", command=Etat_1, bg = "white", relief=FLAT)
button_ia = Button(fenetre_choix, text = "Reseau indisponible",font="arial 12 bold",command=Etat_2, bg = "white", relief=FLAT)
taille_x_l = Label(fenetre_choix, bg = "#00B3D7")
taille_y_b = Label(fenetre_choix, bg = "#00B3D7")
info_ip = Label(fenetre_choix, text = "Quelle est l'etat du reseau ?", bg = "#00B3D7")
 
taille_x_l.pack(side=TOP,padx=380,pady=20)
button_heber.pack(side=TOP,padx=50,pady=10)
button_rej.pack(side=TOP,padx=50,pady=10)
button_ia.pack(side=TOP,padx=50,pady=10)
taille_y_b.pack(side=TOP,pady=80)
info_ip.pack(side=BOTTOM)
 
 
 
Etat_reseau = StringVar()
Etat_reseau.set("Bon") #0: bon 1:moyen 2:mauvais
 
 
tcpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcpsock.bind(("",50000))
 
 
newthread_Ecoute = Ecoute(ip, port, clientsocket, Etat_reseau)
newthread_Ecoute.start()
 
 
fenetre_choix.mainloop()
Client:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import socket
 
connexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connexion.connect(("localhost", 50000))
 
 
while True:
        try:
            msgServ = connexion.recv(1024) # on recoit le message
 
            print("message du Serveur", msgServ.decode('latin-1'))
            #paquethandler(msgClient) # on le gére
        except:
            pass
Merci de votre aide

PS: Je suis un noob