Skip to content

Commit

Permalink
Add example for streams into README
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Feb 14, 2015
1 parent eaf44ba commit f1ba9c5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Documentation

See http://aiozmq.readthedocs.org

Simple client-server RPC example::
Simple high-level client-server RPC example::

import asyncio
import aiozmq.rpc
Expand Down Expand Up @@ -39,6 +39,35 @@ Simple client-server RPC example::

asyncio.get_event_loop().run_until_complete(go())

Low-level RPC example::

import asyncio
import aiozmq
import zmq

@asyncio.coroutine
def go():
router = yield from aiozmq.create_zmq_stream(
zmq.ROUTER,
bind='tcp://127.0.0.1:*')

addr = list(router.transport.bindings())[0]
dealer = yield from aiozmq.create_zmq_stream(
zmq.DEALER,
connect=addr)

for i in range(10):
msg = (b'data', b'ask', str(i).encode('utf-8'))
dealer.write(msg)
data = yield from router.read()
router.write(data)
answer = yield from dealer.read()
print(answer)
dealer.close()
router.close()

asyncio.get_event_loop().run_until_complete(go())


Requirements
------------
Expand Down

0 comments on commit f1ba9c5

Please sign in to comment.