diff --git a/Canguru/tentandop.py b/Canguru/tentandop.py index 7419fc7c57b7026a0de7f35f56c716fca3906e18..a753efa61a62e2464d412e174f35cb0f1d7c34aa 100755 --- a/Canguru/tentandop.py +++ b/Canguru/tentandop.py @@ -115,6 +115,7 @@ class Protocol(): def token (): global TOKEN global StartTime + global queue udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) tokenMessage = Protocol() dest = (HOST, SEND_PORT) @@ -126,6 +127,14 @@ def token (): tokenMessage.type = str(0) msg = tokenMessage.getEmpacotar() udp.sendto (msg,dest) + if (TOKEN == 1): + #print 'ESTOU COM O TOKEN' + if (not queue.empty()): + msg = queue.get () + udp.sendto (msg[1], dest) + print 'ENVIANDO' + #else: + #print 'A FILA ESTA VAZIA' udp.close() def client (): @@ -135,6 +144,7 @@ def client (): udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) dest = (HOST, SEND_PORT) protocolMessage = Protocol() + global queue queue = Queue.PriorityQueue() while True: protocolMessage.setDestiny() @@ -145,16 +155,8 @@ def client (): protocolMessage.setCRC32() msg = protocolMessage.getEmpacotar() queue.put ((protocolMessage.priority, msg)) - print queue.queue - HighPriority = queue.queue[0] - print HighPriority[0] - if (TOKEN == 1): - print 'POSSO ENVIAR MSG' - if (not queue.empty()): - msg = queue.get () - udp.sendto (msg[1], dest) - print 'ENVIANDO' - print msg[1] + if (not queue.empty()): + HighPriority = queue.queue[0] threadServer._Thread__stop() threadToken._Thread__stop() udp.close() @@ -175,12 +177,7 @@ def server (): #print msg protocolDescompactMessage.setDesempacota(msg) #print protocolDescompactMessage.msg - print protocolDescompactMessage.type - print msg - print msg[1] if (msg[1] == '1'): - print 'LA' - print msg print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg if (protocolDescompactMessage.type == '0' and TOKEN == 0):