Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
ffefb533
Commit
ffefb533
authored
13 years ago
by
Antoine Millet
Browse files
Options
Downloads
Patches
Plain Diff
Added a basic usage
parent
8db42ff2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
doc/fundamentals.rst
+54
-0
54 additions, 0 deletions
doc/fundamentals.rst
with
54 additions
and
0 deletions
doc/fundamentals.rst
+
54
−
0
View file @
ffefb533
...
...
@@ -18,6 +18,60 @@ Features
* **Fallback mode:** for compatibility with olders sjRpc.
Basic usage
-----------
Server side, create the handler
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The handler is a simple object with a dict interface (getitem) responsible of
the association between the remote-function name and the locally executed
callable. The :class:`sjrpc.utils.Handler` class allow you to define
an handle with a simple class extending this one::
>>> class MyHandler(RpcHandler):
... def random(self, min=0, max=100):
... return random.randint(min, max)
...
>>> handler = MyHandler()
But if you want to use a standard dictionnary, this is exactly the same::
>>> handler = {'random': lambda min, max: random.randint(min, max)}
Server side, create the :class:`~sjrpc.core.RpcServer` instance
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The last thing to do on the server side is to launch the server itself::
>>> from sjrpc.server import RpcServer
>>> serv = RpcServer.from_addr('127.0.0.1', 1337n conn_kw=dict(handler=handler))
>>> serv.run()
.. note::
`conn_args` and `conn_kw` are the arguments which are automatically passed
to each client :class:`~sjrpc.core.RpcConnection` instanciation. In this
example, we just pass a default handler.
Client side, just connect !
^^^^^^^^^^^^^^^^^^^^^^^^^^^
For a basic client usage, the only thing you have to do is to create the
:class:`RpcConnection` instance to the server, nothing more simple::
>>> conn = RpcConnection.from_addr('127.0.0.1', 1337)
>>> print conn.call('random')
42
You can also use a proxy to simplify remote calls::
>>> from sjrpc.utils import ConnectionProxy
>>> proxy = ConnectionProxy(conn)
>>> print proxy.random(min=42, max=1000)
587
Multiplexing & protocols
------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment