Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

Why a ZeroMQ example does not work?

$
0
0

I am new in Python/ ZeroMQ, so show forbearance if it is an easy question.

I try to run some examples, but it does not work really good.
Here is the hwserver/hwclient example of the ZeroMQ-Guide:


SERVER

#   Hello World server in Python#   Binds REP socket to tcp://*:5555#   Expects b"Hello" from client, replies with b"World"#import timeimport zmqcontext = zmq.Context()socket = context.socket(zmq.REP)socket.bind("tcp://*:5555")while True:    message = socket.recv()               #  Wait for next request from client    print("Received request: %s" % message)    time.sleep(1)                         #  Do some 'work'    print( "teeest" )    socket.send(b"World")                 #  Send reply back to client

CLIENT

#    Hello World client in Python#    Connects REQ socket to tcp://localhost:5555#    Sends "Hello" to server, expects "World" back#import zmqcontext = zmq.Context()print("Connecting to hello world server…")    #  Socket to talk to serversocket = context.socket(zmq.REQ)socket.connect("tcp://localhost:5555")for request in range(10):                     #  Do 10 requests,    #                                         #  waiting each time for a response    print("Sending request %s …" % request)    socket.send(b"Hello")    message = socket.recv()                   #  Get the reply.    print("Received reply %s [ %s ]" % (request, message))

And I am getting this output:

Connecting to hello world server…Sending request 0 …Received reply 0 [ b'World' ]Sending request 1 …Received reply 1 [ b'World' ]Sending request 2 …Received reply 2 [ b'World' ]Sending request 3 …Received reply 3 [ b'World' ]Sending request 4 …Received reply 4 [ b'World' ]Sending request 5 …Received reply 5 [ b'World' ]Sending request 6 …Received reply 6 [ b'World' ]Sending request 7 …Received reply 7 [ b'World' ]Sending request 8 …Received reply 8 [ b'World' ]Sending request 9 …Received reply 9 [ b'World' ]Process finished with exit code 0

Could somebody tell me why I dont get the prints of the server like "Received request" and "teeeest"?

Thank you!


Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>