From 06118deab8c478d7ad11128d8a9e1f0fef8602ca Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Sun, 6 Nov 2016 16:29:47 -0200 Subject: [PATCH] Token add --- Canguru/CanguruChat.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Canguru/CanguruChat.py b/Canguru/CanguruChat.py index 8859fb0..6ce88e9 100755 --- a/Canguru/CanguruChat.py +++ b/Canguru/CanguruChat.py @@ -33,7 +33,7 @@ import binascii MACHINE_ID = 1 SEND_PORT = 5000 # Porta que o Servidor envia -RECV_PORT = 5000 # Porta que o Servidor recebe +RECV_PORT = 5000 # Porta que o Servidor recebe class Protocol(): def __init__ (self): @@ -66,6 +66,12 @@ class Protocol(): self.priority = raw_input() self.priority = str(self.priority) + def setType (self): + if (self.msg == 'token'): + self.type = str(0) + else: + self.type = str(1) + #set message def setMessage(self): sys.stdout.write('Mensagem: ') @@ -106,15 +112,19 @@ def client (): protocolMessage.setDestiny() protocolMessage.setPriority() protocolMessage.setMessage() + protocolMessage.setType() protocolMessage.setSizeof() protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() while protocolMessage.msg <> 'exit': + if (protocolMessage.type == 0): + print 'Vou mandar o token' udp.sendto (msg, dest) protocolMessage = Protocol() protocolMessage.setDestiny() protocolMessage.setPriority() protocolMessage.setMessage() + protocolMessage.setType() protocolMessage.setSizeof() protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() @@ -132,7 +142,9 @@ def server (): while True: msg, cliente = udp.recvfrom(1024) protocolDescompactMessage.setDesempacota(msg) - if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): + if (protocolDescompactMessage.type == '0'): + print 'RECEBI O TOKEN' + if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): print msg print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg else: @@ -142,9 +154,9 @@ def server (): #------------------MAIN-----------------# if len(sys.argv) > 1: - AUX = RECV_PORT - RECV_PORT = SEND_PORT - SEND_PORT = AUX + TOKEN = 1 + print 'COMECEI COM O TOKEN' + print "Ip da proxima maquina" HOST = raw_input() threadServer = threading.Thread(target=server) -- GitLab