Commit 00fee016 authored by Antoine Millet's avatar Antoine Millet

Updated examples.

parent b732bc8b
#!/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()
#!/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()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment