views:

1707

answers:

3

I followed the instructions at:

How To Build An Apple Push Notification Provider Server When I run the php script on my MacOSX or on Windows using Parallel desktop, the script works. But as soon as I run it on my hosting I get the message:

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in provider.php on line 23
Failed to connect 110 Connection timed out

Does this have to do with the certificates? If so how can I make a certificate that could work on the computer where my hosting is located.

+1  A: 

Yes you need a certificate. THis is explained in the Apple docs. One catch, you will probably need to convert the cert to .pem format. The .pem cert needs to include both the certificate and the RSA private key.

Here is a good site to read: http://www.macoscoders.com/2009/05/17/iphone-apple-push-notification-service-apns/

My pem looks like:

Bag Attributes
    friendlyName: Apple Development Push Services: <my data>
    localKeyID: <my local key in hexascii> 
subject=/UID=com.my.push.sandbox1/CN=Apple Development Push Services: <my data>/C=US
issuer=/C=US/O=Apple Inc./OU=Apple Worldwide Developer Relations/CN=Apple Worldwide Developer Relations Certification Authority
-----BEGIN CERTIFICATE-----
<my certificate data omitted>
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
<my key data omitted>
-----END RSA PRIVATE KEY-----
zaph
Thank you zaph for your response. I do have the certificates and the .pem files else it wouldn't work on my local machine, but if I upload that certificate to my hosting together with my php file. It gives the above time-out. Do I need a different certificate for on the hosting computer? Because I can only access it by FTP.
Mark
Check that the .pem file has both parts. On a local Mac it may be getting the private key from the Keychain. I am running on another machine that does not have a Keychain entry.
zaph
+1  A: 

Your hosting provider probably does not allow outbound connections to ports 2195 and 2196. Most shared hosting providers do not have those ports open. You might need to get a VPS or you can also try UrbanAirship which provides Apple Notification Service integration and is free for a certain limit per month.

paul_sns
A: 

I found the simplest and cheapest solution was to request a dedicated IP from your hosting company. At Blue Host it was $2.50 a month. With this dedicated IP, they were willing to open ports 2195 and 2196.

Mups