grille_client.py 1.14 KB
Newer Older
Mestari Yousra's avatar
Mestari Yousra committed
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
import zmq

context = zmq.Context()

#  Socket to talk to server

socket = context.socket(zmq.DEALER)
socket.connect("tcp://147.250.9.87:5555")

def grille_client(J):
	for i in range(5):
		#verifier que les bateaux sont bien mis
		empty,validation=socket.recv_multipart()
		while validation.decode() != "ok":
			#question de la tete
			empty,reponse=socket.recv_multipart()
			print(reponse.decode())
			#reponse de la tete
			position_avant=input()
			socket.send_multipart([b'',position_avant.encode()])
			empty,reponse=socket.recv_multipart()
			#tete illegale
			if reponse.decode()=="Cette case est deja occupee":
				print(reponse.decode())
				empty,validation=socket.recv_multipart()
			#tete legale
			else:
				#question de la queue
				print(reponse.decode())
				#reponse de la queue
				position_queue=input()
				socket.send_multipart([b'',position_queue.encode()])
				empty,reponse=socket.recv_multipart()
				#queue illegale
				if reponse.decode()=="Cette combinaison n'est pas valable":
					print(reponse.decode())
					empty,validation=socket.recv_multipart()
				#queue legale
				else:
					empty,validation=socket.recv_multipart()
	return