File: echofuture.py

package info (click to toggle)
pyzmq 27.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,984 kB
  • sloc: python: 15,189; ansic: 285; makefile: 169; sh: 85
file content (22 lines) | stat: -rw-r--r-- 439 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
"""A basic ZMQ echo server with zmq.eventloop.future"""

from tornado import ioloop

import zmq
from zmq.eventloop.future import Context


async def echo(sock):
    while True:
        msg = await sock.recv_multipart()
        await sock.send_multipart(msg)


ctx = Context.instance()
s = ctx.socket(zmq.ROUTER)
s.bind('tcp://127.0.0.1:5555')

loop = ioloop.IOLoop.current()
loop.spawn_callback(echo, s)
loop.start()