Search code examples
pythontcpzeromq

Why a ZeroMQ demo code doesn't work on Win10?


I'm learning how to communicate with a server from a client/trader perspective. It looks like ZeroMQ is the go-to package dealing with this. I found this piece of demo code on the website. The thing is it doesn't produce the desired output as in this post: Why a ZeroMQ example does not work?.

Whenever I tried to run the code, it freezes and nothing ever comes out of it. I can't even comment and ask my question there, in the post above, because my credit isn't great enough.

For your information, I try to run the code on a Windows 10 computer.

I believe I've changed the setup of the inbound and outbound of TCP connections on firewall, which I read was what needed to be done with Win-10. I also thought maybe I should change the way the directory is written from "//" to "\\". Didn't work either. In addition, I've tried to change local tcp to "tcp://127.0.0.1:5555" and it still didn't.
Here's the code,

import time
import zmq

context = zmq.Context()
socket=context.socket(zmq.REP)
socket.bind("tcp://*:5555")

while True:
    message=socket.recv()
    print("Received request: %s" % message)

    time.sleep(1)
    print("test")
    socket.send(b"World")

import zmq

context = zmq.Context()

print("Connecting to hello world server...")
socket = context.socket(zmq.REQ)
socket.connect("tcp://*:5555")

for request in range(10):
    print("Sending request %s..." % request)
    socket.send(b"Hello")

    message = socket.recv()
    print("Received reply %s [%s]" % (request, message))

Any suggestion would be really appreciated.


Solution

  • Why a ZeroMQ demo code doesn't work on Win10?

    Because of this SLOC :

    socket.connect( "tcp://*:5555" ) # production-grade code always ERROR checks a call
    

    This call ought have specified a tcp://-TransportClass a valid address:port to go and try to .connect(), which must failed by the above posted try to attempt a "*:port"

    Repair it & you ought be ready to proceed into the beautiful gardens of the Zen of Zero.