Newer
Older
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
#!/usr/bin/env python
'''
sjRpc client example.
'''
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):
print 'Local call to client_random'
return random.randint(min, max)
# Get arguments from the command line:
if len(sys.argv) < 3:
print 'Usage: %s <listening address> <listening port>' % sys.argv[0]
sys.exit(2)
address = sys.argv[1]
port = int(sys.argv[2])
# Create the rpc connection:
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)
print 'Random = %s' % (conn.call('proxy', 'client_random'), )
conn.shutdown()