Trying to send simple messages with zeromq in python between two hosts -
script running on machine 1
import zmq context = zmq.context() socket = context.socket(zmq.sub) socket.bind("tcp://127.0.0.1:5000") print "socket bound" while true: print "waiting message" message = socket.recv() print "message received: " + str(message)
this script gets socket.recv() , never returns call.
the process sends data runs on machine2
import zmq context = zmq.context() socket = context.socket(zmq.pub) print "socket created" socket.connect("tcp://machine2:5000") print "socket connected" in range(1, 3): print "about send " + str(i) socket.send("hello " + str(i)) print "sent " + str(i) print "about close socket" socket.close() print "socket closed"
executes completion, never finishes...
$ python bar.py socket created socket connected send 1 sent 1 send 2 sent 2 close socket socket closed
i'm doing wrong, how create 'queue' receive multiple messages publishes on remote hosts?
just need bind socket , set option using setsockopt given below. fine..
import zmq import socket context = zmq.context() socket = context.socket(zmq.sub) socket.setsockopt(zmq.subscribe, "") socket.bind("tcp://*:5000") print "socket bound" while true: print "waiting message" message = socket.recv() print "message received: " + str(message)
Comments
Post a Comment