import communicator import sys import torch PORT = 1232 HOSTADDR = "container1" myid = sys.argv[1] print(f"My id: {myid}") if myid == '0': print("I am server. Waiting for msg...") serv = communicator.Server(PORT) result = serv.recv() print(f"Received obj of type {str(type(result))} and content:\n{str(result)}") if myid == '1': print("I am client. Sending msg...") loc = (HOSTADDR, PORT) sender = communicator.Client() testobj = torch.randn(4, 10) sender.send(loc, testobj) print(f"Sent {str(testobj)}")
# -*- coding: utf-8 -*- """ Created on Wed Nov 18 16:53:50 2020 @author: Konstantina """ from GaussianGenerator import GaussianGenerator import numpy as np import threading import communicator import matplotlib.pyplot as plt PORT = 1232 serv_model = communicator.Server(PORT) PORT2 = 1233 serv_grad = communicator.Server(PORT2) w = np.array([0.0,0.0,0.0]) def model_server(): print("model server thread is up") global w while True: result = serv_model.recv() #print(f"Received obj of type {str(type(result))} and content:\n{str(result)}") #send weights serv_model.reply(w, PORT) #print(f"Sent obj of type {str(type(w))} and content:\n{str(w)}")
import communicator client = communicator.Client('localhost', 1234) server = communicator.Server('localhost', 1234) server.start() client.start() server.stop()