From ce1714e9ebd3169bdeb6e2173ef97a5b34654bb2 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Wed, 9 Nov 2016 21:03:33 -0200 Subject: [PATCH] quase --- maybe.py | 47 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 39 deletions(-) diff --git a/maybe.py b/maybe.py index 21f825d..9c042ad 100755 --- a/maybe.py +++ b/maybe.py @@ -78,12 +78,6 @@ class Protocol(): self.priority = raw_input() self.priority = 7 - int(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: ') @@ -134,25 +128,17 @@ def token (): tokenMessage.type = str(0) tokenMessage.priority = str(PRIORITY_TOKEN) msg = tokenMessage.getEmpacotar() - print msg udp.sendto (msg,dest) #time.sleep(2) if (not queue.empty()): m = queue.queue[0] - print m - print PRIORITY_TOKEN - print m[0] - print TOKEN if (int(PRIORITY_TOKEN) >= int(m[0])): - print 'envie' queue.get() msgProtocol.setDesempacota(m[1]) msgProtocol.priority = str(7) msg = msgProtocol.getEmpacotar() udp.sendto (msg, dest) - - print 'ENVIANDO' time.sleep(1) while (RECEBIDA == 0): print 'ENVIANDO NOVAMENTE A MSG' @@ -176,8 +162,6 @@ def client (): protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() queue.put ((protocolMessage.priority, msg)) - if (not queue.empty()): - HighPriority = queue.queue[0] threadServer._Thread__stop() threadToken._Thread__stop() except: @@ -201,55 +185,40 @@ def server (): while True: msg, cliente = udp.recvfrom(1024) protocolDescompactMessage.setDesempacota(msg) - #print msg - #Recebi o token - print msg + if (protocolDescompactMessage.type == '1' and int(MACHINE_ID) == int(protocolDescompactMessage.origin)): - print 'LELELEL' + print 'SETANDO A PRIORIDADE' PRIORITY_TOKEN = protocolDescompactMessage.priority + print PRIORITY_TOKEN + print 'EU RECEBI A MSG QUE ENVIEI' + elif (protocolDescompactMessage.type == '0' and TOKEN == 0): print 'RECEBI O TOKEN' TOKEN = 1 StartTime = time.time() - #A msg foi enviada com sucesso - elif (msg[1] == '2' and int(MACHINE_ID) == int(protocolDescompactMessage.destiny)): - print 'A MENSAGEM FOI ENVIADA COM SUCESSO' - RECEBIDA = 1 - - #Erro no envio - elif (msg[1] == '3' and int(MACHINE_ID) == int(protocolDescompactMessage.destiny)): - RECEBIDA = 0 - #A msg e pra mim elif (msg[1] == '1' and int(MACHINE_ID) == int(protocolDescompactMessage.destiny)): - print msg[4] - #protocolDescompactMessage.crc = "8888888"#caga tdo udp.sendto(msg,dest) if (protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32()): print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg - - udp.sendto (msg, dest) else: print 'ERRO DE MENSAGEM' udp.sendto (msg, dest) #A msg n e pra mim - elif (msg[1] == '1' or msg[2] == '2' or msg[3] == '3'): + elif (msg[1] == '1'): if (not queue.empty()): top = queue.queue[0] HighPriorat = int(top[0]) if (HighPriorat < int(msg[4])): - print msg aux1.setDesempacota(msg) aux1.priority = str(HighPriorat) msg = aux1.getEmpacotar() - print msg + print msg udp.sendto (msg, dest) - - - + udp.close() #------------------MAIN-----------------# -- GitLab