title: Unable to connect to ssl://gateway.push.apple.com:2195 (Connection timed out)
body: <p>I'm going crazy with Apple push notification!
  I've developed my app and test notifications following <a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" rel="nofollow noreferrer">Ray Wanderlich</a> tutorial and everything worked fine until I changed the file .pem with the distribution one and changed the connection string from gateway.sandbox.push-apple.com to gateway.push-apple.com.</p>
  
  <p>Now if I try to send a message the server returns</p>
  
  <pre><code>Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to     ssl://gateway.push.apple.com:2195 (Connection timed out)
  Failed to connect: 110 Connection timed out
  </code></pre>
  
  <p>The php file and the .pem file are on a TMDHosting: I try to ask them if port number 2195 is closed because googling I found that the error means port is closed. </p>
  
  <p>Though, I can't understand if the error is linked to the certificate or to the server.</p>
  
  <p>The strange things is that if I follow the procedure with the Terminal to test the .pem file , everything seems to work</p>
  
  <pre><code>CONNECTED(00000003)
      depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c)     2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
      verify error:num=20:unable to get local issuer certificate
      verify return:0
      ---
      Certificate chain
       0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc/OU=Internet     Services/CN=gateway.push.apple.com
         i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c)     2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
       1 s:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c)     2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
         i:/O=Entrust.net/OU=www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)/OU=(c)     1999 Entrust.net Limited/CN=Entrust.net Certification Authority (2048)
  ---
  Server certificate
  -----BEGIN CERTIFICATE-----
      MIIEXTCC..........
  -----END CERTIFICATE-----
      subject=/C=US/ST=California/L=Cupertino/O=Apple Inc/OU=Internet         Services/CN=gateway.push.apple.com
      issuer=/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c)      2009 Entrust, Inc./CN=Entrust Certification Authority - L1C
      ---
      No client certificate CA names sent
      ---
      SSL handshake has read 2541 bytes and written 2039 bytes
      ---
      New, TLSv1/SSLv3, Cipher is AES256-SHA
      Server public key is 1024 bit
      Secure Renegotiation IS supported
     Compression: NONE
     Expansion: NONE
      SSL-Session:
      Protocol  : TLSv1
      Cipher    : AES256-SHA
          Session-ID: 
          Session-ID-ctx: 
          Master-Key:     CBA98981BB512ED2FDF0C003F4556FDDA564BEBBEFC6528C37D8E0336BC141AEC6D7E014568B334B8330FFFE266E8CB4
      Key-Arg   : None
      Start Time: 1332945845
      Timeout   : 300 (sec)
      Verify return code: 0 (ok)
  ---
  </code></pre>
  
  <p>This lets me to think that it's not a .pem problem...</p>
  
  <p>Am I wrong?</p>
  
  <p>I've already read all the similar question here, and tried to change the port number from 2195 to 30, but nothing changes.
  Hints?</p>
  
  <p><strong>EDIT</strong>: I found <a href="https://stackoverflow.com/questions/1444355/iphone-push-notification-unable-to-connect-to-the-ssl-server">that</a> and seems equal to my problem: TMDHosting told me </p>
  
  <blockquote>
    <p>...you are located under a shared hosting environment and opening a
    port for you will be not possible. However note that the address to
    which you are making a connection on port 2195 is not associate with
    our server. In other words you are trying to make a connection to a
    remote server on port 2195. In order to make this connection to the
    port specified above you should make sure that the port is opened for
    incoming connections on the remote server and not on the server on
    which your account with us relies.</p>
  </blockquote>
  
  <p>Do I need a VPS?</p>
  
  <p><strong>EDIT2</strong>:</p>
  
  <p>In the tutorial I followed I found</p>
  
  <blockquote>
    <p>.. you will need a server that is connected to the internet. Push
    notifications are always sent by a server. For development you can use
    your Mac as the server (which we’ll do in this tutorial) but for
    production use, you need at least something like a VPS (Virtual
    Private Server). A cheap shared hosting account is not good enough.
    You need to be able to run a background process on the server, install
    an SSL certificate, and be able to make outgoing TLS connections on
    certain ports. Most shared hosting providers do not let you do this,
    although they might if you ask. However, I really recommend using a
    VPS host such as Linode.</p>
  </blockquote>
  
  <p>At last I think I do need a VPS. Can you confirm for sure?
  <strong>But why if I send push notification with the sandbox server it works properly without VPS?</strong></p>
  
  <p><strong><em>LAST UPDATE</em></strong>: (hope to help someone) it seems like there was a bug because the right thing is that I cannot send push notification not to the sandbox nor to the production server from my  hosting (TMDHosting): my shared hosting has not the 2195 port open. Changed provider: everything works.</p>