def pingd(self, packet, conn): conn.sendall(packet.reply()) def quit(self, packet, conn): self.send_to_all(packet, conn) conn.close() self.clients.pop(conn, None) raise SystemExit() def finish(self, packet, conn): self.send_to_all(packet, conn) os.kill(os.getpid(), signal.SIGINT) raise SystemExit() def shutdown(self): self.socket.close() logging.info('socket closed') for conn in list(self.clients.keys()): conn.close() logging.info('connections closed') for th in map(attrgetter('thread'), list(self.clients.values())): th.join() logging.info('threads closed') raise SystemExit() if __name__ == '__main__': configure_logging('Server') args = get_cmd_args() CommandServer.run_server(args.host, args.port)
for client in list(self.clients.keys()): conn.sendall(reply) conn.close() self.clients.pop(conn, None) raise SystemExit() def finish(self, packet): reply = packet.reply() for client in list(self.clients.keys()): client.sendall(reply) os.kill(os.getpid(), signal.SIGINT) raise SystemExit() def shutdown(self): self.socket.close() logging.info('socket closed') for conn in list(self.clients.keys()): conn.close() logging.info('connections closed') for th in map(attrgetter('thread'), list(self.clients.values())): th.join() logging.info('threads closed') if os.path.exists(self.PID_FILE): os.remove(self.PID_FILE) raise SystemExit() if __name__ == '__main__': configure_logging('Server') args = get_cmd_args() CommandServer.run_server(args.host, args.port)
def connected(self, packet): self.session = packet.session print('{} {}'.format(packet.cmd, packet.session)) def pong(self, packet): print(packet.cmd) def pongd(self, packet): print('{} {}'.format(packet.cmd, packet.data)) def delayed(self, packet): print('{} {}'.format(packet.cmd, packet.data)) def ackquit(self, packet): print('{} {}'.format(packet.cmd, packet.session)) self.shutdown() def ackfinish(self, packet): print(packet.cmd) self.shutdown() def shutdown(self): self.socket.close() logging.info('socket closed') raise SystemExit() if __name__ == '__main__': configure_logging('Client') args = get_cmd_args() CommandClient.run_client(args.host, args.port)
getattr(self, packet.__class__.__name__.lower())(packet) break def connected(self, packet): self.session = packet.session print('{} {}'.format(packet.cmd, packet.session)) def pong(self, packet): print(packet.cmd) def pongd(self, packet): print('{} {}'.format(packet.cmd, packet.data)) def ackquit(self, packet): print('{} {}'.format(packet.cmd, packet.session)) self.shutdown() def ackfinish(self, packet): print(packet.cmd) self.shutdown() def shutdown(self): self.socket.close() logging.info('socket closed') raise SystemExit() if __name__ == '__main__': configure_logging('Client') args = get_cmd_args() CommandClient.run_client(args.host, args.port)