ios - Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195' from server side -


i'm working on mac app use ios push notifications. want send notification php script on server. code in app works registering remote notification , receive them. use php script send notification , works too:

 <?php  // device token here (without spaces): $devicetoken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';  // private key's passphrase here: $passphrase = 'myprivatekeypassword';  // alert message here: $message = 'new push notification!';  //badge $badge = 1;  $ctx = stream_context_create(); stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);  // open connection apns server $fp = stream_socket_client( 'ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, stream_client_connect|stream_client_persistent, $ctx);  if (!$fp)   exit("failed connect: $err $errstr" . php_eol);   echo 'connected apns' . php_eol;   // create payload body $body['aps'] = array(     'alert' => $message,     'badge' => $badge,     'sound' => 'newmessage.wav' );  // encode payload json $payload = json_encode($body);  // build binary notification $msg = chr(0) . pack('n', 32) . pack('h*', $devicetoken) . pack('n', strlen($payload))  . $payload;  // send server $result = fwrite($fp, $msg, strlen($msg));  if (!$result)     echo 'error, notification not sent' . php_eol; else     echo 'notification sent!' . php_eol;   // close connection server  fclose($fp); ?> 

my problem if run script terminal on imac other mac system, works , notifications sent, if upload on server doesn't work. certificate valid , it's in same folder of script. when try run script on server. gives following error:

warning: stream_socket_client() [function.stream-socket-client]: unable connect ssl://gateway.sandbox.push.apple.com:2195 (connection timed out) in /home/iphmuvxr/public_html/schedueling/push_notification.php on line 25

sounds didn't open port on server. please open port , try again.

you can verify following command:

$telnet gateway.sandbox.push.apple.com 2195 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -