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

Funcionando chamando um arquivo apenas

parent d1e5f746
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
#################### Protocol #############################
# Marca - Destino - Prioridade - Tamamnho - Messagem - CRC#
###########################################################
......@@ -7,8 +8,9 @@ import threading
import sys
import binascii
HOST = "200.17.202.49" # Endereco IP do Servidor
PORT = 5000 # Porta que o Servidor es
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
class FuncThread(threading.Thread):
def __init__(self, target, *args):
......@@ -21,7 +23,7 @@ class FuncThread(threading.Thread):
class Protocol():
def __init__ ():
self.marca = '10101010' #Marca
self.marca = "~" #Marca
#Get sizeof message
def sizeof (self, msg):
......@@ -43,6 +45,9 @@ class Protocol():
print 'Mensagem:'
self.msg = raw_input()
#def empacotar():
# return self.marca + self.sizemsg
#Get CRC32
def getCRC32(msg):
buff = (binascii.crc32(msg) & 0xFFFFFFFF)
......@@ -64,7 +69,7 @@ class queue(object):
def client ():
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dest = (HOST, PORT)
dest = (HOST, SEND_PORT)
print 'Para sair digite exit\n'
print 'Mensagem:'
......@@ -82,16 +87,24 @@ def client ():
def server ():
print 'Estou no Server'
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
orig = (HOST, PORT)
orig = (HOST, RECV_PORT)
udp.bind(orig)
while True:
hostname, cliente = udp.recvfrom(1024)
msg, cliente = udp.recvfrom(1024)
print cliente, msg
print hostname,':', msg
print 'Estou no Server'
udp.close()
#def killThread ():
if len(sys.argv) > 1:
AUX = RECV_PORT
RECV_PORT = SEND_PORT
SEND_PORT = AUX
if __name__ == '__main__':
threadServer = FuncThread (server)
threadServer.start()
threadClient = FuncThread (client)
threadClient.start()
threadClient.join()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment