为什么ZeroMQ演示代码在Win10上不起作用?

问题描述 投票:1回答:1

我正在从客户端/交易商的角度学习如何与服务器通信。看起来ZeroMQ是处理此问题的首选软件包。我在网站上找到了这段演示代码。关键是它无法产生所需的输出,如这篇文章:Why a ZeroMQ example does not work?

[每当我尝试运行代码时,它都会冻结,并且从此都不会产生任何结果。在上面的帖子中,我什至无法发表评论并提出问题,因为我的信誉还不够。

作为参考,我尝试在Windows 10计算机上运行代码。

我相信我已经更改了防火墙上TCP连接的入站和出站设置,我读到的是Win-10要做的事情。我还认为也许应该将目录的写入方式从“ //”更改为“ \\”。也没用。另外,我尝试将本地tcp更改为“ tcp://127.0.0.1:5555”,但仍然没有。这是代码,

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))

任何建议将不胜感激。

python tcp zeromq
1个回答
1
投票

如果从未使用过ZeroMQ,在这里您可以先看看"ZeroMQ Principles in less than Five Seconds",然后再深入研究更多细节]]


Q

“为什么ZeroMQ演示代码在Win10上不起作用?”

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

此呼叫应已指定tcp:// -TransportClass有效的

address:port
并尝试进入.connect(),但必须通过上述尝试<*:port“的尝试来失败>

修复它,您应该准备进入零之禅的美丽花园。

© www.soinside.com 2019 - 2024. All rights reserved.