From d81a44db61854d368e3807d1b66e0b699bce2128 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Sun, 6 Nov 2016 16:48:53 -0200 Subject: [PATCH] Tratando erro token --- Canguru/CanguruChat.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Canguru/CanguruChat.py b/Canguru/CanguruChat.py index 6ce88e9..731c66e 100755 --- a/Canguru/CanguruChat.py +++ b/Canguru/CanguruChat.py @@ -31,6 +31,8 @@ import threading import sys import binascii +global TOKEN +TOKEN = 0 MACHINE_ID = 1 SEND_PORT = 5000 # Porta que o Servidor envia RECV_PORT = 5000 # Porta que o Servidor recebe @@ -104,6 +106,7 @@ class Protocol(): return "%08X" % buff def client (): + global TOKEN try: udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) dest = (HOST, SEND_PORT) @@ -117,9 +120,12 @@ def client (): protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() while protocolMessage.msg <> 'exit': - if (protocolMessage.type == 0): + if (protocolMessage.type == 0 and TOKEN == 1): print 'Vou mandar o token' - udp.sendto (msg, dest) + TOKEN = 0 + else: + print "ERRO, N ESTOU COM O TOKEN" + udp.sendto (msg, dest) protocolMessage = Protocol() protocolMessage.setDestiny() protocolMessage.setPriority() @@ -135,6 +141,7 @@ def client (): threadServer._Thread__stop() def server (): + global TOKEN udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) orig = ('', RECV_PORT) udp.bind(orig) @@ -142,8 +149,9 @@ def server (): while True: msg, cliente = udp.recvfrom(1024) protocolDescompactMessage.setDesempacota(msg) - if (protocolDescompactMessage.type == '0'): + if (protocolDescompactMessage.type == '0' and TOKEN == 0): print 'RECEBI O TOKEN' + TOKEN = 1 if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): print msg print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg -- GitLab