GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — PythonRpcFramework/client.py at master · crylearner/PythonRpcFramework Expand file tree/ Copy pathclient.pyMore file actions 91 lines (72 loc) · 2.38 KB / Copy pathclient.pyFile metadata and controls91 lines (72 loc) · 2.38 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 ''' Created on 2015年7月12日 @author: sunshyran ''' import threading import time from rpc.json.client.Client import Client from rpc.json.message.Request import Request class HelloProxy(object): def __init__(self): super().__init__() def bindClient(self, client): self.client = client def sayHello(self): req = Request() req.ID = 1 req.method = 'HelloService.sayHello' return self.client.request(req) def whoAreYou(self): req = Request() req.ID = 2 req.method = 'HelloService.whoAreYou' return self.client.request(req) def add(self, a, b): req = Request() req.ID = 3 req.method = 'HelloService.add' req.params = {'a':a, 'b':b} return self.client.request(req) # def attach(self, callback): # req = Request() # req.ID = 4 # req.method = 'HelloService.attach' # cid = self.client.listen(self.callback_decorator(callback)) # req.params = {'callback':cid} # return self.client.request(req) # # def detach(self, callback): # req = Request() # req.ID = 5 # req.method = 'HelloService.detach' # cid = self.client.get_identity(self.callback_decorator(callback)) # req.params = {'callback':cid} # # self.client.request(req) # self.client.cancelListener(self.callback_decorator(callback)) def callback_decorator(self, callback, callbacklist={}): ''' \ 可根据需要,对完整的参数列表做过滤 ''' def __callback(*args): callback(*args) if not callback in callbacklist: callbacklist[callback] = __callback return callbacklist[callback] if __name__ == '__main__': client = Client('127.0.0.1', 12345) client.start() thread = threading.Thread(target = client.run, daemon = True).start() proxy = HelloProxy() proxy.bindClient(client) def callback(x): print(x) print(proxy.sayHello()) print('cccc') print(proxy.whoAreYou()) print(proxy.add(1, 2)) # print(proxy.attach(callback)) # time.sleep(1) # print(proxy.detach(callback)) # time.sleep(1) print('dddd') client.stop() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |