diff --git a/Canguru/Cliente.py b/Canguru/Cliente.py old mode 100644 new mode 100755 index 5ecabb81a037e18e00fa988ea5f9534fccce0b4b..6c2b76659cb82189ebe5ada3437e5b8276d72574 --- a/Canguru/Cliente.py +++ b/Canguru/Cliente.py @@ -1,3 +1,4 @@ +#!/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__': - threadClient = FuncThread (client) - threadClient.start() - threadClient.join() +threadServer = FuncThread (server) +threadServer.start() +threadClient = FuncThread (client) +threadClient.start()