Skip to content

Instantly share code, notes, and snippets.

@yishenggudou
Created November 16, 2012 08:36
Show Gist options
  • Save yishenggudou/4085511 to your computer and use it in GitHub Desktop.
Save yishenggudou/4085511 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2011 timger
# +Author timger
# +Gtalk&Email yishenggudou@gmail.com
# +Msn yishenggudou@msn.cn
# +Weibo @timger http://t.sina.com/zhanghaibo
# +twitter @yishenggudou http://twitter.com/yishenggudou
# Licensed under the MIT License, Version 2.0 (the "License");
import zmq
def main():
try:
context = zmq.Context(1)
# Socket facing clients
frontend = context.socket(zmq.SUB)
frontend.bind("tcp://*:50001")
frontend.setsockopt(zmq.SUBSCRIBE, "")
# Socket facing services
backend = context.socket(zmq.PUB)
backend.bind("tcp://*:50002")
zmq.device(zmq.FORWARDER, frontend, backend)
except Exception, e:
print e
print "bringing down zmq device"
finally:
pass
frontend.close()
backend.close()
context.term()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment