From 8e19d9bcfa13c4b032fbfe66ebde899df6341375 Mon Sep 17 00:00:00 2001
From: Fernando Erd <fce15@inf.ufpr.br>
Date: Mon, 7 Nov 2016 16:46:21 -0200
Subject: [PATCH] destiny machine funfa

---
 Canguru/tentandop.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/Canguru/tentandop.py b/Canguru/tentandop.py
index 3adcc4d..d3e66ff 100755
--- a/Canguru/tentandop.py
+++ b/Canguru/tentandop.py
@@ -140,8 +140,6 @@ def client ():
     try:
         global TOKEN
         global HighPriority
-        udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-        dest = (HOST, SEND_PORT)
         protocolMessage = Protocol()
         global queue
         queue = Queue.PriorityQueue()
@@ -158,7 +156,6 @@ def client ():
                 HighPriority = queue.queue[0]
         threadServer._Thread__stop()
         threadToken._Thread__stop()
-        udp.close()
     except:
         print 'OPS, ALGO OCORREU ERRADO'
         threadServer._Thread__stop()
@@ -169,20 +166,24 @@ def server ():
     global StartTime
     udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
     orig = ('', RECV_PORT)
+    dest = (HOST, SEND_PORT)
     udp.bind(orig)
     protocolDescompactMessage = Protocol()
+    
     while True:
         msg, cliente = udp.recvfrom(1024)
-        #print msg
         protocolDescompactMessage.setDesempacota(msg)
-        #print protocolDescompactMessage.msg
-        if (msg[1] == '1'):
+        
+        if (msg[1] == '1' and int(MACHINE_ID) == int(protocolDescompactMessage.destiny)):
             print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg
-    
-       	if (protocolDescompactMessage.type == '0' and TOKEN == 0):
+        elif (msg[1] == '1'):
+            udp.sendto (msg, dest)
+       	
+        if (protocolDescompactMessage.type == '0' and TOKEN == 0):
             print 'RECEBI O TOKEN'
             TOKEN = 1
             StartTime = time.time()
+    
     udp.close()
     
 #------------------MAIN-----------------#
-- 
GitLab