diff options
| author | Loic Guegan <manzerberdes@gmx.com> | 2019-05-12 10:14:28 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerberdes@gmx.com> | 2019-05-12 10:53:33 +0200 |
| commit | bbd9151d7fa3500582c62474da2ce39ea151a63c (patch) | |
| tree | 98454b2d09049befb5d41503af282bbb1a5509b6 /client | |
| parent | 9de3c7586dc97209aef5b436d0c5e7657f711c72 (diff) | |
Switch to udp
Diffstat (limited to 'client')
| -rw-r--r-- | client/client.py | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/client/client.py b/client/client.py index f87eaba..ea72c27 100644 --- a/client/client.py +++ b/client/client.py @@ -12,19 +12,13 @@ LARGEUR_BLOCK = 10 NB_BLOCKS = 30 LARGEUR_ECRAN = LARGEUR_BLOCK * NB_BLOCKS -def connect(): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((ip_adress,port)) - return s +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + def sendData(data): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((ip_adress,port)) - s.sendall(data.encode('utf-8')) - s.send('#EOF\n'.encode('utf-8')) - received = s.recv(RESP_BUFFER_LENGTH) - s.close() - return received + s.sendto(data,(ip_adress,port)) + received = s.recvfrom(1024) + return received[0] def newGame(): received = sendData('{"type": "new-game"}') @@ -39,6 +33,7 @@ def update(gameId = 1, direction = None): received = sendData(json.dumps(data)) return json.loads(received) + # ---------- END SOCKETS ---------- LARGEUR_BLOCK = 20 |
