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

Two machines talking

parent f36a01e2
No related branches found
No related tags found
No related merge requests found
...@@ -31,9 +31,8 @@ import threading ...@@ -31,9 +31,8 @@ import threading
import sys import sys
import binascii import binascii
HOST = "127.0.0.1" # Endereco IP do Servidor
SEND_PORT = 5000 # Porta que o Servidor envia 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 MACHINE_ID = 1
class Protocol(): class Protocol():
...@@ -123,13 +122,12 @@ def client (): ...@@ -123,13 +122,12 @@ def client ():
def server (): def server ():
udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
orig = (HOST, RECV_PORT) orig = ('', RECV_PORT)
udp.bind(orig) udp.bind(orig)
protocolDescompactMessage = Protocol() protocolDescompactMessage = Protocol()
while True: while True:
msg, cliente = udp.recvfrom(1024) msg, cliente = udp.recvfrom(1024)
protocolDescompactMessage.setDesempacota(msg) protocolDescompactMessage.setDesempacota(msg)
if protocolDescompactMessage.destiny == MACHINE_ID:
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
...@@ -143,7 +141,8 @@ if len(sys.argv) > 1: ...@@ -143,7 +141,8 @@ if len(sys.argv) > 1:
AUX = RECV_PORT AUX = RECV_PORT
RECV_PORT = SEND_PORT RECV_PORT = SEND_PORT
SEND_PORT = AUX SEND_PORT = AUX
print "Ip da proxima maquina"
HOST = raw_input()
threadServer = threading.Thread(target=server) threadServer = threading.Thread(target=server)
threadClient = threading.Thread(target=client) threadClient = threading.Thread(target=client)
threadServer.start() threadServer.start()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment