Skip to content
Snippets Groups Projects
Commit b4e81273 authored by Fernando Erd's avatar Fernando Erd :ok_hand:
Browse files

so mando msg quando estou com o token

parent 96b15920
No related branches found
No related tags found
No related merge requests found
...@@ -115,6 +115,7 @@ class Protocol(): ...@@ -115,6 +115,7 @@ class Protocol():
def token (): def token ():
global TOKEN global TOKEN
global StartTime global StartTime
global queue
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tokenMessage = Protocol() tokenMessage = Protocol()
dest = (HOST, SEND_PORT) dest = (HOST, SEND_PORT)
...@@ -126,6 +127,14 @@ def token (): ...@@ -126,6 +127,14 @@ def token ():
tokenMessage.type = str(0) tokenMessage.type = str(0)
msg = tokenMessage.getEmpacotar() msg = tokenMessage.getEmpacotar()
udp.sendto (msg,dest) 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() udp.close()
def client (): def client ():
...@@ -135,6 +144,7 @@ def client (): ...@@ -135,6 +144,7 @@ def client ():
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dest = (HOST, SEND_PORT) dest = (HOST, SEND_PORT)
protocolMessage = Protocol() protocolMessage = Protocol()
global queue
queue = Queue.PriorityQueue() queue = Queue.PriorityQueue()
while True: while True:
protocolMessage.setDestiny() protocolMessage.setDestiny()
...@@ -145,16 +155,8 @@ def client (): ...@@ -145,16 +155,8 @@ def client ():
protocolMessage.setCRC32() protocolMessage.setCRC32()
msg = protocolMessage.getEmpacotar() msg = protocolMessage.getEmpacotar()
queue.put ((protocolMessage.priority, msg)) 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()): if (not queue.empty()):
msg = queue.get () HighPriority = queue.queue[0]
udp.sendto (msg[1], dest)
print 'ENVIANDO'
print msg[1]
threadServer._Thread__stop() threadServer._Thread__stop()
threadToken._Thread__stop() threadToken._Thread__stop()
udp.close() udp.close()
...@@ -175,12 +177,7 @@ def server (): ...@@ -175,12 +177,7 @@ def server ():
#print msg #print msg
protocolDescompactMessage.setDesempacota(msg) protocolDescompactMessage.setDesempacota(msg)
#print protocolDescompactMessage.msg #print protocolDescompactMessage.msg
print protocolDescompactMessage.type
print msg
print msg[1]
if (msg[1] == '1'): if (msg[1] == '1'):
print 'LA'
print msg
print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg
if (protocolDescompactMessage.type == '0' and TOKEN == 0): if (protocolDescompactMessage.type == '0' and TOKEN == 0):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment