Describe linux/zeromq安装 here.

{{{ apt-get install libtool autoconf automake uuid-dev g++ wget http://download.zeromq.org/zeromq-3.2.3.tar.gz tar zxf zeromq-3.2.3.tar.gz cd zeromq-3.2.3 ./configure --build=sparc-linux make make install

}}}

pyzmq {{{ pip install pyzmq }}} client.py {{{#!highlight python import sys import zmq

Socket to talk to server

context = zmq.Context() socket = context.socket(zmq.SUB)

print "Collecting updates from weather server..." socket.connect ("tcp://localhost:5556")

Subscribe to zipcode, default is NYC, 10001

zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001" socket.setsockopt(zmq.SUBSCRIBE, zip_filter)

Process 5 updates

total_temp = 0 for update_nbr in range (5): string = socket.recv() zipcode, temperature, relhumidity = string.split() total_temp += int(temperature) print "Average temperature for zipcode '%s' was %dF" % (zip_filter, total_temp / update_nbr) }}}

server.py {{{#!highlight python import zmq import random

context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind("tcp://*:5556")

while True: zipcode = random.randrange(1,100000) temperature = random.randrange(1,215) - 80 relhumidity = random.randrange(1,50) + 10

socket.send("%d %d %d" % (zipcode, temperature, relhumidity))

}}}

Comments !