From 668627b2691d0ecb53c5b488031baae5a2aeaa26 Mon Sep 17 00:00:00 2001 From: Fernando Erd <fce15@inf.ufpr.br> Date: Thu, 3 Nov 2016 22:37:31 -0200 Subject: [PATCH] Two machines talking --- Canguru/CanguruChat.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Canguru/CanguruChat.py b/Canguru/CanguruChat.py index 97f7628..1312425 100755 --- a/Canguru/CanguruChat.py +++ b/Canguru/CanguruChat.py @@ -31,9 +31,8 @@ import threading import sys 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 +RECV_PORT = 5000 # Porta que o Servidor recebe MACHINE_ID = 1 class Protocol(): @@ -123,18 +122,17 @@ def client (): def server (): udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - orig = (HOST, RECV_PORT) + orig = ('', RECV_PORT) udp.bind(orig) protocolDescompactMessage = Protocol() while True: msg, cliente = udp.recvfrom(1024) protocolDescompactMessage.setDesempacota(msg) - if protocolDescompactMessage.destiny == MACHINE_ID: - if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): - print msg - print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg - else: - print 'ERRO, A MENSAGEM FOI RECIBIDA ERRADA' + if protocolDescompactMessage.crc == protocolDescompactMessage.getCRC32(): + print msg + print '\n' + protocolDescompactMessage.origin + ' Escreveu: ' + protocolDescompactMessage.msg + else: + print 'ERRO, A MENSAGEM FOI RECIBIDA ERRADA' udp.close() #------------------MAIN-----------------# @@ -143,8 +141,9 @@ if len(sys.argv) > 1: AUX = RECV_PORT RECV_PORT = SEND_PORT SEND_PORT = AUX - +print "Ip da proxima maquina" +HOST = raw_input() threadServer = threading.Thread(target=server) threadClient = threading.Thread(target=client) threadServer.start() -threadClient.start() \ No newline at end of file +threadClient.start() -- GitLab