diff --git a/Canguru/CanguruChat.py b/Canguru/CanguruChat.py index 6ce88e9795c4c4eee64116ca3d174c1188c914f4..731c66e145f1f0c4385f3bfdb0c5e8462355c9f1 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