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

Token add

parent 93038531
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,12 @@ class Protocol(): ...@@ -66,6 +66,12 @@ class Protocol():
self.priority = raw_input() self.priority = raw_input()
self.priority = str(self.priority) self.priority = str(self.priority)
def setType (self):
if (self.msg == 'token'):
self.type = str(0)
else:
self.type = str(1)
#set message #set message
def setMessage(self): def setMessage(self):
sys.stdout.write('Mensagem: ') sys.stdout.write('Mensagem: ')
...@@ -106,15 +112,19 @@ def client (): ...@@ -106,15 +112,19 @@ def client ():
protocolMessage.setDestiny() protocolMessage.setDestiny()
protocolMessage.setPriority() protocolMessage.setPriority()
protocolMessage.setMessage() protocolMessage.setMessage()
protocolMessage.setType()
protocolMessage.setSizeof() protocolMessage.setSizeof()
protocolMessage.setCRC32() protocolMessage.setCRC32()
msg = protocolMessage.getEmpacotar() msg = protocolMessage.getEmpacotar()
while protocolMessage.msg <> 'exit': while protocolMessage.msg <> 'exit':
if (protocolMessage.type == 0):
print 'Vou mandar o token'
udp.sendto (msg, dest) udp.sendto (msg, dest)
protocolMessage = Protocol() protocolMessage = Protocol()
protocolMessage.setDestiny() protocolMessage.setDestiny()
protocolMessage.setPriority() protocolMessage.setPriority()
protocolMessage.setMessage() protocolMessage.setMessage()
protocolMessage.setType()
protocolMessage.setSizeof() protocolMessage.setSizeof()
protocolMessage.setCRC32() protocolMessage.setCRC32()
msg = protocolMessage.getEmpacotar() msg = protocolMessage.getEmpacotar()
...@@ -132,6 +142,8 @@ def server (): ...@@ -132,6 +142,8 @@ def server ():
while True: while True:
msg, cliente = udp.recvfrom(1024) msg, cliente = udp.recvfrom(1024)
protocolDescompactMessage.setDesempacota(msg) protocolDescompactMessage.setDesempacota(msg)
if (protocolDescompactMessage.type == '0'):
print 'RECEBI O TOKEN'
if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32():
print msg print msg
print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg
...@@ -142,9 +154,9 @@ def server (): ...@@ -142,9 +154,9 @@ def server ():
#------------------MAIN-----------------# #------------------MAIN-----------------#
if len(sys.argv) > 1: if len(sys.argv) > 1:
AUX = RECV_PORT TOKEN = 1
RECV_PORT = SEND_PORT print 'COMECEI COM O TOKEN'
SEND_PORT = AUX
print "Ip da proxima maquina" print "Ip da proxima maquina"
HOST = raw_input() HOST = raw_input()
threadServer = threading.Thread(target=server) threadServer = threading.Thread(target=server)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment