def __init__(self, main): Thread.__init__(self, daemon=True) self.bot = main self.log = logging.getLogger('RPC') self.server = jsonrpc.Server( jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp( addr=(self.bot.botconfig["bot"]["rpcbind"], self.bot.botconfig["bot"]["rpcport"]))) self.server.register_function(self.importModule) self.server.register_function(self.deportModule) self.server.register_function(self.loadModule) self.server.register_function(self.unloadModule) self.server.register_function(self.reloadModule) self.server.register_function(self.redoModule) self.server.register_function(self.getLoadedModules) self.server.register_function(self.pluginCommand) self.server.register_function(self.setPluginVar) self.server.register_function(self.getPluginVar) self.server.register_function(self.quit) self.server.register_function(self.eval) self.server.register_function(self.exec) self.start()
def j2testserver(): port = randint(40000, 60000) server = jsonrpc.Server(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", port))) server.register_function(sample) server.register_instance(_sample(), name="obj") Thread(target=server.serve, daemon=True).start() sleep(0.2) # Give the serve() time to set up the serversocket yield (server, port) server._Server__transport.close()
def connect(host, port): return jsonrpc.ServerProxy(jsonrpc.JsonRpc20(), jsonrpc.TransportTcpIp(addr=(host, port), timeout=60.0))
def client(port, v=2): return jsonrpc.ServerProxy( (jsonrpc.JsonRpc20 if v == 2 else jsonrpc.JsonRpc10)(), jsonrpc.TransportTcpIp(addr=("127.0.0.1", port), timeout=2.0))