I'm attempting to push notifications to my iPhone, which I've successfully done using PHP. However, I'm unable to open a socket connection to Apple's push servers using C#. I don't think there's a problem with the certificate itself, since I'm able to successfully push notifications using this code in PHP:
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'cert.pem');
$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
fwrite($fp, $msg);
When I try to authenticate in C# using the code below, Apple closes the connection right away. I get this exception: "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Default, false);
I basically took all my code from this question: http://stackoverflow.com/questions/1056083/c-iphone-push-server
I thought it might be a problem with the certificate since I don't think C# allows you to just load .PEM files programmatically. I used OpenSSL to convert it to a .PFX file, but I still have the same problem.
Any idea how I can troubleshoot this (possible certificate) problem?