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

Queue is working

parent c603e864
No related branches found
No related tags found
No related merge requests found
......@@ -31,10 +31,13 @@ import threading
import sys
import binascii
import time
import Queue
global TOKEN
global StartTime
global HighPriority
StartTime = 0
HighPriority = 10
TOKEN = 0
MACHINE_ID = 1
SEND_PORT = 5000 # Porta que o Servidor envia
......@@ -69,7 +72,7 @@ class Protocol():
print 'Entrada Invalida, Por favor escolha entre 1 a 7'
sys.stdout.write('Prioridade: ')
self.priority = raw_input()
self.priority = str(self.priority)
self.priority = 7 - int(self.priority)
def setType (self):
if (self.msg == 'token'):
......@@ -93,7 +96,7 @@ class Protocol():
self.crc = "%08X" % buff
def getEmpacotar(self):
return self.marca + self.type + self.destiny + self.origin + self.priority + self.sizemsg + self.marca + self.msg + self.marca + self.crc
return self.marca + self.type + self.destiny + self.origin + str(self.priority) + self.sizemsg + self.marca + self.msg + self.marca + self.crc
def setDesempacota(self, msg):
self.marca = msg[0]
......@@ -118,7 +121,7 @@ def token ():
while True:
EndTime = time.time()
if (EndTime - StartTime >= 10 and TOKEN == 1):
print 'Vou mandar o token'
print 'MANDEI O TOKEN'
TOKEN = 0
tokenMessage.Type = str(0)
msg = tokenMessage.getEmpacotar()
......@@ -126,29 +129,28 @@ def token ():
udp.close()
def client ():
global TOKEN
try:
global TOKEN
global HighPriority
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dest = (HOST, SEND_PORT)
print 'Para sair digite exit\n'
protocolMessage = Protocol()
protocolMessage.setDestiny()
protocolMessage.setPriority()
protocolMessage.setMessage()
protocolMessage.setType()
protocolMessage.setSizeof()
protocolMessage.setCRC32()
msg = protocolMessage.getEmpacotar()
while protocolMessage.msg <> 'exit':
udp.sendto (msg, dest)
protocolMessage = Protocol()
queue = Queue.PriorityQueue()
while True:
protocolMessage.setDestiny()
protocolMessage.setPriority()
protocolMessage.setMessage()
protocolMessage.setType()
protocolMessage.Type = str(1)
protocolMessage.setSizeof()
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'
#udp.sendto (msg, dest)
threadServer._Thread__stop()
threadToken._Thread__stop()
udp.close()
......@@ -166,9 +168,7 @@ def server ():
protocolDescompactMessage = Protocol()
while True:
msg, cliente = udp.recvfrom(1024)
print msg
protocolDescompactMessage.setDesempacota(msg)
print protocolDescompactMessage.type
if (protocolDescompactMessage.type == '0' and TOKEN == 0):
print 'RECEBI O TOKEN'
TOKEN = 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment