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
| listeClient=[]
def f_thread(clisock):
loopEnd = True
t=0
#On cherche le premier livreur disponible:
num_livreur=0
while restaurant[num_livreur].occupe==True:
num_livreur +=1
restaurant[num_livreur].occupe=True
while loopEnd:
data = clisock.recv(2048)
if t==0:
print data
num = data[6]
t+=1
clisock.send(data)
if not data:
clisock.shutdown(0)
listeClient.remove(clisock)
print "Le client"+num+" a ete livre par le livreur"+str(restaurant[num_livreur].num)
restaurant[num_livreur].occupe=False
loopEnd = False
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('',8001))
sock.listen(5)
while True:
clisock, addr = sock.accept()
listeClient.append(clisock)
print "Un client a passe commande"
t = threading.Thread(target=f_thread, args=(clisock,))
t.start() |
Partager