forked from mbr/tinyrpc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import zmq | ||
|
||
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol | ||
from tinyrpc.transports.zmq import ZmqClientTransport | ||
from tinyrpc import RPCClient | ||
|
||
ctx = zmq.Context() | ||
|
||
rpc_client = RPCClient( | ||
JSONRPCProtocol(), | ||
ZmqClientTransport.create(ctx, 'tcp://127.0.0.1:5001') | ||
) | ||
|
||
remote_server = rpc_client.get_proxy() | ||
|
||
# call a method called 'reverse_string' with a single string argument | ||
result = remote_server.reverse_string('Hello, World!') | ||
|
||
print "Server answered:", result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
import zmq | ||
|
||
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol | ||
from tinyrpc.transports.zmq import ZmqServerTransport | ||
from tinyrpc.server import RPCServer | ||
from tinyrpc.dispatch import RPCDispatcher | ||
|
||
ctx = zmq.Context() | ||
dispatcher = RPCDispatcher() | ||
transport = ZmqServerTransport.create(ctx, 'tcp://127.0.0.1:5001') | ||
|
||
rpc_server = RPCServer( | ||
transport, | ||
JSONRPCProtocol(), | ||
dispatcher | ||
) | ||
|
||
@dispatcher.public | ||
def reverse_string(s): | ||
return s[::-1] | ||
|
||
rpc_server.serve_forever() |