本文共 1025 字,大约阅读时间需要 3 分钟。
$ sudo apt-get install zeromq-bin libzmq0 libzmq-dev libzmq-dbg
sudo add-apt-repository ppa:chris-lea/zeromqsudo apt-get update
sudo apt-get install python-zeromq
http://zeromq.github.com/pyzmq/
$ sudo apt-get install autoconf automake$ sudo pip install pyzmq
$ git clone git://github.com/zeromq/pyzmq.git$ cd pyzmq$ python setup.py configure --zmq=/path/to/zmq/prefix$ python setup.py install
easy_install pyzmq
例 33.2. server.py
$ cat server.pyimport zmqcontext = zmq.Context()socket = context.socket(zmq.REP)socket.bind("tcp://127.0.0.1:5000")while True: msg = socket.recv() print "Got", msg socket.send(msg)
例 33.3. client.py
$ cat client.pyimport zmqcontext = zmq.Context()socket = context.socket(zmq.REQ)socket.connect("tcp://127.0.0.1:5000")for i in range(10): msg = "msg %s" % i socket.send(msg) print "Sending", msg msg_in = socket.recv()
sudo gem install zmq
原文出处:Netkiller 系列 手札
本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。