How to use Apple Push Notifications if you can't use port 2195?

12,196

Solution 1

In order to send the notifications to the device need to enable 2195 port in the firewall. For security reasons some organizations disabling these ports in the firewall. 2196 port is used for feedback services and this port also should open in the firewall. Without opening these ports messages cannot deliver to APNS.

Solution 2

I believe the following is what you are looking for

$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = 'AppCert.pem';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["458e5939b2xxxxxxxxxxx3"], "aps": {"alert": "test message one!"}}');

$curl_scraped_page = curl_exec($ch);

more information can be found here: Apple push notification with cURL

Share:
12,196
John Doe
Author by

John Doe

Updated on June 18, 2022

Comments

  • John Doe
    John Doe almost 2 years

    I have developed a script using stream_socket_client() and it works on my localhost but when I try to use it online (with Fatcow.com web hosting) it won't work. I receive the following error:

    Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection refused) in .../send-notification.php on line 18 Failed to connect 111 Connection refused

    This is line 18:

    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

    I know that the password for the .pem file is correct. The question becomes if I can't use this port what do I do? Is there any free service that I can use? I know that port 80 is open.

    I've heard that using the curl() function will work but have been unsuccessful so far.

    I would really appreciate getting pointed in the right direction.

  • Ans
    Ans over 8 years
    are you $url = 'https://gateway.sandbox.push.apple.com:2195'; will work when 2195 is blocked? This is what we are discussing here.
  • Liam Sorsby
    Liam Sorsby over 8 years
    @Ans The OP never mentions that the port is blocked. This is just an asumption. The OP just says that it is refused.
  • Ajay Gabani
    Ajay Gabani about 7 years
    How to open these ports on Amazon EC2 server?