diff --git a/doc/examples/client.py b/doc/examples/client.py index 75a4283f7b9d4d5c1e1ef2a9d2190532f495fe3b..60fb0491a18908485ea6f2032657abb7ce54f101 100644 --- a/doc/examples/client.py +++ b/doc/examples/client.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ''' -sjRpc client example. +Simple sjRpc client example. ''' from __future__ import absolute_import @@ -9,12 +9,10 @@ from __future__ import absolute_import import sys import random import threading -import time from sjrpc.core import RpcConnection from sjrpc.utils import RpcHandler - class MyClientHandler(RpcHandler): def client_random(self, min=0, max=100): @@ -33,8 +31,10 @@ port = int(sys.argv[2]) conn = RpcConnection.from_addr(address, port, handler=MyClientHandler()) # Run the connection mainloop in another thread: -threading.Thread(target=conn.run).start() -time.sleep(0.1) +t = threading.Thread(target=conn.run) +t.daemon = True +t.start() + print 'Random = %s' % (conn.call('proxy', 'client_random'), ) conn.shutdown() diff --git a/doc/examples/server.py b/doc/examples/server.py index 571b98998927a0e1eebcc7205fda977454b09a40..87f6d6d1c8c670fda213f53f4669b696fb99194f 100644 --- a/doc/examples/server.py +++ b/doc/examples/server.py @@ -1,14 +1,14 @@ #!/usr/bin/env python ''' -Server mode using Gevent. +Simple sjRpc server. ''' from __future__ import absolute_import import sys import random -from sjrpc.server import GreenRpcServer +from sjrpc.server import RpcServer from sjrpc.utils import RpcHandler, pass_connection @@ -22,7 +22,7 @@ class MyHandler(RpcHandler): ''' Example of bidirectionnal RPC. When the peer call this method, the server forward the call of the specified method the peer, and return - returned value. + the value returned by the peer. ''' return conn.call(method, *args, **kwargs) @@ -34,9 +34,7 @@ address = sys.argv[1] port = int(sys.argv[2]) # Create the server instance: -rpcserver = GreenRpcServer(address, port, conn_kw=dict(handler=MyHandler())) - -# conn_kw (and conn_args) are arguments which are automatically passed on -# client RpcConnection instances. +rpcserver = RpcServer.from_addr(address, port, conn_kw=dict(handler=MyHandler())) +rpcserver.loop.debug = True rpcserver.run()