[zeromq-dev] simple python example for 0MQ/2.0
Pavol Malosek
malosek at fastmq.com
Wed Oct 7 09:18:24 CEST 2009
Hello Tom,
I gave a try to your examples and seems working for me (Python 2.5.2).
$python server.py
waiting for message
received message: test
Check the wire with some t/wireshark if message is send out from client, if
no add some sleep at the end of the client (have a look into
perf/python/remote_thr.py)
malo
>----- Original Message -----
>From: tom
>To: zeromq-dev at lists.zeromq.org
>Sent: Wednesday, October 07, 2009 7:51 AM
>Subject: [zeromq-dev] simple python example for 0MQ/2.0
>
>
>hello,
>
>
>i'm trying to use 0MQ/2.0 under python(2.5). the performance tests work
fine so i think i have done
>everything right in setting up my environment (winXP).
>
>
>now i'm trying to make a simple client - server example but the server
never receives messages from the client
>
>
>mqserver.py:
>-------------------------------------------------------------------
>import libpyzmq
>
>
>def main ():
> server_address = "tcp://127.0.0.1:3251"
>
>
> ctx = libpyzmq.Context(1, 1)
> s = libpyzmq.Socket(ctx, libpyzmq.SUB)
> s.setsockopt (libpyzmq.SUBSCRIBE , "*");
> s.bind(server_address)
>
>
> print "waiting for message"
> amsg = s.recv()
> print "received message: %s " % (amsg, )
>
>
>
>if __name__ == "__main__":
> main ()
>-------------------------------------------------------------------
>
>
>mqclient.py:
>-------------------------------------------------------------------
>import sys
>import libpyzmq
>
>
>def main ():
> server_address = "tcp://127.0.0.1:3251"
>
> ctx = libpyzmq.Context(1, 1)
> s = libpyzmq.Socket (ctx, libpyzmq.PUB)
> s.connect(server_address)
>
>
> msg = sys.argv [1]
> print "sending message: %s " % (msg, )
>
> s.send(msg)
> print "ended sending messages"
>
>
>if __name__ == "__main__":
> main ()
>-------------------------------------------------------------------
>
>
>as output of the client i get :
>>mqclient.py bla
>sending message: bla
>ended sending messages
>>_
>
>
>but the server gets stuck on the "amsg = s.recv()" line, as seen by the
output:
>
>
>>mqserver.py
>waiting for message
>
>
>i realize that i run the server and client on the same machine, but that
shouldn't make a difference (should it ?).
>i have also tried the real ip address instead of 127.0.0.1 but nothing
works, is there something
>
>
>any help would be appreciated,
>thanks,
>tom
More information about the zeromq-dev
mailing list