Пример #1
0
class Node(object):
    def __init__(self, config):
        data = json.loads(open(config).read())
        empLocation = data['empLocation']
        neighbs = data['neighbours']
        self.neighbours = []

        for port in neighbs:
            self.neighbours.append(Location('127.0.0.1', port))

        self.empLocation = empLocation
        self.groupLocation = Location('239.192.1.100', 50000)
        self.myLocation = Location('127.0.0.1', int(data['myLocation']))
        self.discoListener = DiscoveryListener()
        self.transListener = TransportListener(
            neighbours=self.neighbours,
            empLocation=self.empLocation,
            node_location=self.myLocation
        )

    def run(self):
        data = self.discoListener.listen(ip=self.groupLocation.ip, port=self.groupLocation.port)
        print('Received client location: ', data)
        self.discoListener.send(ip=data.ip, port=data.port, data=self.myLocation.get_tuple())

        print('Sent my location. Waiting for transport request')

        self.transListener.listen()
Пример #2
0
class Client(object):
    def __init__(self):
        self.discoClient = DiscoveryClient()
        self.transClient = TransportClient()
        self.myLocation = Location("127.0.0.1", 3456)
        self.groupLocation = Location("239.192.1.100", 50000)

    def run(self):
        self.discoClient.send(location=self.groupLocation.get_tuple(), data=self.myLocation)
        maven_location = self.discoClient.receive(ip=self.myLocation.ip, port=self.myLocation.port)
        print("First node is: ", maven_location)

        self.transClient.setLocation(maven_location)
        employees = self.transClient.getEmployees(b"client")

        print(len(employees))
        print(employees)
Пример #3
0
    def __init__(self, config):
        data = json.loads(open(config).read())
        empLocation = data['empLocation']
        neighbs = data['neighbours']
        self.neighbours = []

        for port in neighbs:
            self.neighbours.append(Location('127.0.0.1', port))

        self.empLocation = empLocation
        self.groupLocation = Location('239.192.1.100', 50000)
        self.myLocation = Location('127.0.0.1', int(data['myLocation']))
        self.discoListener = DiscoveryListener()
        self.transListener = TransportListener(
            neighbours=self.neighbours,
            empLocation=self.empLocation,
            node_location=self.myLocation
        )
Пример #4
0
 def __init__(self):
     self.discoClient = DiscoveryClient()
     self.transClient = TransportClient()
     self.myLocation = Location("127.0.0.1", 3456)
     self.groupLocation = Location("239.192.1.100", 50000)