简体   繁体   中英

how can i use zeromq to broadcast on AWS

i just wrote a very simple python script like this

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.

both two scripts run on the VPS(amazon web service).

do i need some settings on AWS?

You need to use the private IP of the EC2 instance. Public IPs in EC2 are provided by NAT mapping and an instance cannot see itself that way.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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