def run_client(address, port, log, log_level): client = EPCClient((address, port), log_traceback=True) if log: level = getattr(logging, log_level.upper()) handler = logging.StreamHandler() handler.setLevel(level) client.logger.addHandler(handler) client.logger.setLevel(level) @client.register_function def pong(*args): print("PONG sending {0}".format(args)) return client.call_sync('echo', [args], timeout=1) print("Server provides these methods:") print(client.methods_sync()) print("Calling (echo 1)") print("Got: {0}".format(client.call_sync('echo', [1]))) print("Calling (ping-pong 111 222 333)") print("Got: {0}".format(client.call_sync('ping-pong', [111, 222, 333]))) print("Closing client...") client.close() print("Closing client... Done!")
def main(port): client = EPCClient(("localhost", port), log_traceback=True) with contextlib.closing(client): print("Server provides these methods:") print(client.methods_sync()) print("Calling (add 1 2 3)") print("Got: {0}".format(client.call_sync('add', [1, 2, 3]))) print("Closing client...") print("Closing client... Done!")
class RemoteREPLClient(Cmd): prompt = 'rrepl> ' def connect(self, address): self.client = EPCClient(address) def default(self, line): try: reply = str(self.client.call_sync('eval', [line], timeout=10)) except Exception as err: reply = str(err) self.stdout.write(reply) self.stdout.write("\n") def do_EOF(self, line): return True