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

Modulates the code

parent 8cf84fd6
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ import binascii
HOST = "127.0.0.1" # Endereco IP do Servidor
SEND_PORT = 5000 # Porta que o Servidor envia
RECV_PORT = 5001 # Porta que o Servidor recebe
MACHINE_ID = 1
class FuncThread(threading.Thread):
def __init__(self, tarset, *args):
......@@ -30,9 +31,15 @@ class FuncThread(threading.Thread):
def run(self):
self._tarset(*self._args)
class Protocol:
def setMarca(self):
class Protocol():
def __init__ (self):
self.marca = "~" #Marca
self.destiny = None
self.origin = str(MACHINE_ID)
self.priority = None
self.msg = None
self.sizemsg = None
self.crc = None
#set destiny message
def setDestiny(self):
......@@ -40,9 +47,6 @@ class Protocol:
self.destiny = raw_input()
self.destiny = str(self.destiny)
def setOrigin(self):
self.origin = "1"
#set Priority messsage
def setPriority(self):
print 'Prioridade:'
......@@ -65,7 +69,7 @@ class Protocol:
buff = (binascii.crc32(self.msg) & 0xFFFFFFFF)
self.crc = "%08X" % buff
def empacotar(self):
def getEmpacotar(self):
return self.marca + self.destiny + self.origin + self.priority + self.marca + self.sizemsg + self.msg + self.crc
def desempacota(self, msg):
......@@ -81,30 +85,27 @@ def client ():
dest = (HOST, SEND_PORT)
print 'Para sair digite exit\n'
print 'Mensagem:'
hostname = socket.sethostname()
#hostname = socket.sethostname()
protocolMessage = Protocol()
protocolMessage.setMarca()
protocolMessage.setDestiny()
protocolMessage.setOrigin()
protocolMessage.setPriority()
protocolMessage.setMessage()
protocolMessage.setSizeof()
protocolMessage.setCRC32()
msg = protocolMessage.empacotar()
msg = protocolMessage.getEmpacotar()
#hostname = socket.sethostname()
while True:
udp.sendto (hostname, dest) # Envia Hostname
#udp.sendto (hostname, dest) # Envia Hostname
udp.sendto (msg, dest) #Envia Mensagem
print 'Mensagem:'
protocolMessage = Protocol()
protocolMessage.setMarca()
protocolMessage.setDestiny()
protocolMessage.setOrigin()
protocolMessage.setPriority()
protocolMessage.setMessage()
protocolMessage.setSizeof()
protocolMessage.setCRC32()
msg = protocolMessage.empacotar()
hostname = socket.sethostname()
msg = protocolMessage.getEmpacotar()
#hostname = socket.sethostname()
udp.close()
def server ():
......@@ -113,9 +114,10 @@ def server ():
orig = (HOST, RECV_PORT)
udp.bind(orig)
while True:
hostname, cliente = udp.recvfrom(1024)
#hostname, cliente = udp.recvfrom(1024)
msg, cliente = udp.recvfrom(1024)
print hostname,':', msg
#print hostname,':', msg
print msg
print 'Estou no Server'
udp.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment