title: zmq.error.ZMQError: Cannot assign requested address
body: <p>I have the following pull - publisher ZMQ schema on an Amazon EC2 machine:</p>
  
  <p>I am working with the Public IP address of my EC2 Amazon machine.</p>
  
  <p>I am trying send data via ZMQ <strong><code>PUSH</code></strong> socket from the client side to ZMQ <strong><code>PULL</code></strong> socket server side, which is this:</p>
  
  <pre><code>import zmq
  from zmq.log.handlers import PUBHandler
  import logging
  # from zmq.asyncio import Context
  
  def main():
      ctx = zmq.Context()
      publisher = ctx.socket(zmq.PUB)
      # publisher.bind("tcp://*:5557")
      publisher.bind("tcp://54.89.25.43:5557")
  
      handler = PUBHandler(publisher)
      logger = logging.getLogger()
      logger.addHandler(handler)
  
      print("Network Manager CNVSS Broker listening")
  
      collector = ctx.socket(zmq.PULL)
      # collector.bind("tcp://*:5558")
      collector.bind("tcp://54.89.25.43:5558")
  
      while True:
          message = collector.recv()
          print("Publishing update %s" % message)
          publisher.send(message)
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>But when I excute this script, I get this error:</p>
  
  <pre><code>(cnvss_nm) ubuntu@ip-172-31-55-72:~/cnvss_nm$ python pull_pub-nm.py 
  Traceback (most recent call last):
    File "pull_pub-nm.py", line 28, in &lt;module&gt;
      main()
    File "pull_pub-nm.py", line 10, in main
      publisher.bind("tcp://54.89.25.43:5557")
    File "zmq/backend/cython/socket.pyx", line 547, in zmq.backend.cython.socket.Socket.bind
    File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc._check_rc
  zmq.error.ZMQError: Cannot assign requested address
  (cnvss_nm) ubuntu@ip-172-31-55-72:~/cnvss_nm$ 
  </code></pre>
  
  <p>I've changed my IP-address to <code>publisher.bind("tcp://*:5557")</code> and <code>collector.bind("tcp://*:5558")</code> in the server side, and my script is running:</p>
  
  <pre><code>(cnvss_nm) ubuntu@ip-x-x-x-x:~/cnvss_nm$ python pull_pub-nm.py 
  Network Manager CNVSS Broker listening
  </code></pre>
  
  <p>But from my <a href="https://pastebin.com/LAcqfbCZ" rel="nofollow noreferrer"><strong>client</strong>-side code</a> ( <a href="https://stackoverflow.com/questions/50422619/zmq-error-zmqerror-cannot-assign-requested-address/50426297?noredirect=1#comment87893867_50426297">added recently</a> ), any data is sent.</p>
  
  <pre><code>#include &lt;zmq.hpp&gt;
  #include &lt;zmq.h&gt;
  #include &lt;iostream&gt;
  #include "zhelpers.hpp"
  
  using namespace std;
  
  int main(int argc, char *argv[])
  {
      zmq::context_t context(1);
      /*
      std::cout &lt;&lt; "Sending message to NM Server…\n" &lt;&lt; std::endl; */
  
      zmq::socket_t subscriber(context, ZMQ_SUB);
      subscriber.connect("tcp://localhost:5557");
      subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);
  
      zmq::socket_t sender(context, ZMQ_PUSH);
      sender.connect("tcp://localhost:5558");
  
      string firstMessage = "Hola, soy el cliente 1";
  
      while (1)
      {
          //  Wait for next request from client
          std::string string = s_recv(subscriber);
  
          std::cout &lt;&lt; "Received request: " &lt;&lt; string &lt;&lt; std::endl;
  
          // Do some 'work'
          // sleep(1);
  
          //  Send reply back to client
          // zmq::message_t message(firstMessage.size() + 1);
  
          // Cualquiera de los dos se puede
          // memcpy(message.data(), firstMessage.c_str(), firstMessage.size() + 1);
          // s_send(sender, "Hola soy un responder 1");
  
          // sender.send(message);
      }
  }
  </code></pre>
  
  <p>I think that my inconvenient is on my EC2 machine network configuration or on the way of setup the IP address of the server.</p>
  
  <p>When I test the clients and server locally, all it works perfectly.</p>
  
  <p>Is there any possibility of performing some forwarding or NAT operation on my EC2 machine?</p>
  
  <p>My clients do not reach the server.</p>
  
  <p>I have the security groups rule the above mentioned ports 5557 and 5558.</p>
  
  <p>How to solve this inconvenience?</p>