无法使用 zeromq 连接到服务器

2018-07-04 16:18:32 +08:00
 BingoXuan
问题描述:我在腾讯云的服务器上用 python 写了一个 zeromq 的 publisher,监听端口 8099。可我在自己电脑写的 subscriber 却不能连接到服务器,一直收不到服务器 publish 出来的信息。
8099 的端口是开放可用的,我直接开了 python 自带的 CGIHTTPServer 是能连接上去。代码方面也是没有问题的,我在 localhost 环境下测试过才部署的。

希望各位提出想法和建议吧~只要不是水的回复都送铜币
1637 次点击
所在节点    Python
7 条回复
BingoXuan
2018-07-04 16:51:54 +08:00
贴一下服务器的部分代码

class ZPub(Pub):

def __init__(self, identity):
super().__init__(identity)
ctx = zmq.Context()
self.pub_socket = ctx.socket(zmq.PUB)
self.pub_socket.setsockopt_string(zmq.IDENTITY, self.identity)
self.pub_socket.bind('tcp://127.0.0.1:8099')
self.lock = threading.Lock()

def _send(self, ts, msg, id_str):
self.lock.acquire()
self.pub_socket.send_multipart([bytes(m, encoding='ascii') for m in [ts, msg, id_str]])
self.lock.release()
BingoXuan
2018-07-04 16:56:10 +08:00
问题已解决:绑定 tcp://*8099

有谁知道具体原因呢?
ThirdFlame
2018-07-04 16:58:13 +08:00
127.0.0.1 不是仅允许本机连接么。
xcai
2018-07-04 16:58:50 +08:00
腾讯云安全组放行端口
tempdban
2018-07-04 17:02:09 +08:00
self.pub_socket.bind('tcp://0.0.0.0:8099')
mosliu
2018-07-04 17:05:20 +08:00
127.0.0.1 是本机 loopback 网卡吧。。。
BingoXuan
2018-07-04 17:07:57 +08:00
@ThirdFlame
@xcai
@tempdban
@mosliu

是的,是我智商掉线。设置防火墙时候知道 0.0.0.0,绑定时候是 127.0.0.1。多谢各位大佬

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/468108

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX