diff --git a/src/communication.py b/src/communication.py index efcac2a..f3d2da0 100644 --- a/src/communication.py +++ b/src/communication.py @@ -39,6 +39,8 @@ class ClusterCommunicationModule(): cont = self.handle_command(data) if not cont: + self.client_sock.close() + self.client_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) break elif data == '[CHECK]': # master side # build docker swarm @@ -90,13 +92,15 @@ class ClusterCommunicationModule(): self.client_sock.send(json.dumps(data).encode()) elif command == '[STOP]': print("Receive STOP signal") - self.node_manager.docker_client.swarm.leave() data = {'host': self.host} self.client_sock.send(f'[STOP_CHECK] {json.dumps(data)}'.encode()) + self.node_manager.docker_client.swarm.leave() + self.node_manager.status = 'none' - self.node_manager.exit() + print("You have leaved the cluster.") + + return False - return True def request(self, host): # master side self.client_sock.connect((host, self.port)) @@ -167,6 +171,7 @@ class ServiceExplorationModule(): while True: data, addr = self.sock.recvfrom(1024) + print(self.node_manager.status) if self.node_manager.status == 'none': if data.decode() == '[EXPLORE]': self.sock.sendto(self.host.encode(), addr)