diff --git a/Canguru/tentandop.py b/Canguru/tentandop.py index 3adcc4d669092af85964f85f235bbf3c91e4b8e3..d3e66ff16ee8cdf7ecba8f943c064662a7953126 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-----------------#