title: Apple Push notification service c++ / boost does not connect
body: <p>I'm currently working on a server-side push notification service with Apple push notification.
  I'm working with boost asio.
  Here's my code : </p>
  
  <pre><code>    void IPhonePush::connection() {
      std::cout &lt;&lt; "Push iPhone connection" &lt;&lt; std::endl;
      std::cout &lt;&lt; getCertif() &lt;&lt; std::endl;
      m_context.set_options(boost::asio::ssl::context::default_workarounds
                            | boost::asio::ssl::context::no_sslv2
                            | boost::asio::ssl::context::single_dh_use);
  
      m_context.set_password_callback(boost::bind(&amp;IPhonePush::get_password, this));
      m_context.use_certificate_chain_file(getCertif().c_str());
      m_context.use_private_key_file(getKey().c_str(), boost::asio::ssl::context::pem);
      boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(tools::Ip::getServiceIp("gateway.push.apple.com")), 2195);
      m_socket.lowest_layer().async_connect(ep,
                                      boost::bind(&amp;IPhonePush::handle_connection,
                                                  this,
                                                  boost::asio::placeholders::error));
    }
  
    void IPhonePush::handle_connection(const boost::system::error_code&amp; error) {
      if (!error) {
        std::cout &lt;&lt; "/////////// Connected to PUSH SERVER !!!" &lt;&lt; std::endl;
        start_handshake();
      } else {
        std::cout &lt;&lt; "/////////// Error Connecting to push: " &lt;&lt; error.message() &lt;&lt; std::endl;
      }
    }
  
    void IPhonePush::start_handshake() {
      m_socket.async_handshake(boost::asio::ssl::stream_base::client,
                               boost::bind(&amp;IPhonePush::handle_handshake,
                                           this,
                                           boost::asio::placeholders::error));
    }
  </code></pre>
  
  <p>The tools::Ip::getServiceIp gives me the ip resolved from the dns :</p>
  
  <pre><code>namespace tools {
    class Ip {
    public:
      static std::string getServiceIp(std::string url) {
        boost::asio::io_service io;
        tcp::resolver resolver(io);
        tcp::resolver::query query(url, "");
        tcp::resolver::iterator iter = resolver.resolve(query);
  
        tcp::endpoint ep;
        while (iter != tcp::resolver::iterator()) {
          ep = *iter++;
          break;
        }
        return ep.address().to_string();
      }
    };
  }
  </code></pre>
  
  <p>The thing is, the async_connect is called, and then nothing... handle_connection is never called not even with an error.</p>
  
  <p><strong>I'm currently wondering if the problem is not coming from resolving the dns into an ip to connect.
  If there another way to ask for a connection with an endpoint pointing towards gateway.push.apple.com directly (without resolving IP) ?</strong></p>
  
  <p>EDIT 1 : </p>
  
  <pre><code>int main() {
       boost::asio::io_service io_push;
       push::IPhonePush ifpush(io_push);
       ifpush.connection();
       io_push.run();
  }
  </code></pre>