File: chat_bridge.py

package info (click to toggle)
python-eventlet 0.40.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,200 kB
  • sloc: python: 25,109; sh: 78; makefile: 32
file content (25 lines) | stat: -rw-r--r-- 708 bytes parent folder | download | duplicates (5)
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
import sys

try:
    from zmq import FORWARDER, PUB, SUB, SUBSCRIBE
    from zmq.devices import Device
except ModuleNotFoundError:
    raise SystemExit("Unable to find required zmq module. "
                     "Please install it before running this example.")


if __name__ == "__main__":
    usage = 'usage: chat_bridge sub_address pub_address'
    if len(sys.argv) != 3:
        print(usage)
        sys.exit(1)

    sub_addr = sys.argv[1]
    pub_addr = sys.argv[2]
    print("Recieving on %s" % sub_addr)
    print("Sending on %s" % pub_addr)
    device = Device(FORWARDER, SUB, PUB)
    device.bind_in(sub_addr)
    device.setsockopt_in(SUBSCRIBE, "")
    device.bind_out(pub_addr)
    device.start()