简体   繁体   English

我如何使用zeromq在AWS上广播

[英]how can i use zeromq to broadcast on AWS

i just wrote a very simple python script like this 我只是这样写了一个非常简单的python脚本

server side: 服务器端:

import zmq
import time

cxt = zmq.Context()
s=cxt.socket(zmq.SUB)
s.bind("tcp://0.0.0.0:1900")

while True:
   s.send("CMD:once")
   print "send once"
   time.sleep(1)

and the client side: 和客户端:

import zmq
import time

cxt = zmq.Context()
s = cxt.socket(zmq.SUB)

s.connect("tcp://127.0.0.1:1900")
s.setsockopt(zmq.SUBSCRIBE,'')

while True:
    msg = s.recv()
    print msg

print "Done".

i works when i use 127.0.0.1 in my client side script.but when i use the public network ip address,my client script can not receive any message. 我在客户端脚本中使用127.0.0.1时可以工作,但是在使用公共网络ip地址时,客户端脚本无法收到任何消息。

both two scripts run on the VPS(amazon web service). 这两个脚本都在VPS(亚马逊网络服务)上运行。

do i need some settings on AWS? 我需要在AWS上进行一些设置吗?

You need to use the private IP of the EC2 instance. 您需要使用EC2实例的专用 IP。 Public IPs in EC2 are provided by NAT mapping and an instance cannot see itself that way. EC2中的公共IP由NAT映射提供,实例无法以这种方式看到自己。

You can also use the public DNS hostname, as seen in the console, because it will resolve to the private IP when queried internally and the public IP when queried externally. 您也可以使用公用 DNS主机名,如在控制台中看到的那样,因为在内部查询时它将解析为私有IP,而在外部查询时将解析为公共IP。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM