Python2.7和Python3.5之间的字节数组和str类型似乎是pyzmq PUB/SUB的问题。 我必须发布/订阅代理一个是python2.7,另一个是python3.5。 我有一个订阅了两个发布/订阅代理的订阅服务器,但它并不接收所有发布的消息。 如何让我的发布/订阅代理订阅并重新发布发布发布在IP:端口上的所有消息?在
样本代码:
def subscribeformessages(self):
context = zmq.Context(1)
xsub = context.socket(zmq.SUB)
xsub_url = "tcp://%s:%s" % (self.ipaddress, self.xsub_url)
xsub.setsockopt_string(zmq.SUBSCRIBE, '')
xsub.setsockopt(zmq.SUBSCRIBE, b'')
if not is_py2:
xsub.setsockopt_string(zmq.SUBSCRIBE, "")
else:
xsub.setsockopt(zmq.SUBSCRIBE, "")
xsub.setsockopt(zmq.SUBSCRIBE, b"")
xsub.setsockopt_unicode(zmq.SUBSCRIBE, u"", encoding='utf-8')
xsub.setsockopt_string(zmq.SUBSCRIBE, u"")
xsub.connect(xsub_url)
try:
while self.running:
try:
time.sleep(.2)
receive = xsub.recv_multipart()
self.print_message_queue.put("sub recv\'d: %s" % receive)
self.pub_local_que.put(receive)
self.publish_queue.put(receive)
except zmq.ZMQError as err:
print(err)
....
发布者示例:
^{pr2}$有什么想法吗?在
我在这里找到了答案:http://pyzmq.readthedocs.io/en/latest/pyversions.html
我将出版物改为:
相关问题 更多 >
编程相关推荐