コード例 #1
0
def connect_to_neighbor(neighbor):
	neighbor_ip = neighbor.split(":")[0]
	neighbor_port = int(neighbor.split(":")[1])
	neighbor_addr = (neighbor_ip, neighbor_port)

	servent_socket.connect(neighbor_addr)

	msg = message_utils.create_id_msg(0)
	servent_socket.send(msg)
コード例 #2
0
def connect_to_neighbor(connection_socket, neighbor):
    # Conecta o servent ao vizinho
    neighbor_ip = neighbor.split(":")[0]
    neighbor_port = int(neighbor.split(":")[1])
    neighbor_addr = (neighbor_ip, neighbor_port)

    connection_socket.connect(neighbor_addr)
    connection_socket.setblocking(0)

    # Envia mensagem ID para o vizinho
    msg = message_utils.create_id_msg(0)
    connection_socket.send(msg)
コード例 #3
0
    print("Formato esperado: python client.py <porto-local> ip: porto")
    sys.exit()

# Obtem dados da entrada
CLIENT_PORT = int(sys.argv[1])
SERVENT_ADDR = sys.argv[2]
SERVENT_IP = SERVENT_ADDR.split(":")[0]
SERVENT_PORT = int(SERVENT_ADDR.split(":")[1])

# Configura o socket que vai se conectar ao servent
client_request_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
servent_addr = (SERVENT_IP, SERVENT_PORT)
client_request_socket.connect(servent_addr)

# Cria e envia mensagem ID dizendo que e' client
msg = message_utils.create_id_msg(CLIENT_PORT)
client_request_socket.send(msg)

# Configura o socket que vai receber as mensagens de resposta
client_response_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_addr = (message_utils.LOCALHOST, CLIENT_PORT)
client_response_socket.bind(client_addr)

nseq = 0

while True:
    try:
        command = input()
        if (analyse_command(command, nseq)):  # Caso o comando seja valido
            last_nseq = nseq
            nseq += 1