On Sat, Jun 9, 2012 at 6:47 AM, catshow <[email protected]> wrote:
> This is what I use to connect via TLS. According to the
> documentation "tls.connect() returns a CleartextStream object."
>
> const tlsOptions = {
> "cert":fs.readFileSync(config.certFile),
> "key":fs.readFileSync(config.keyFile),
> "passphrase":config.passphrase
> };
>
> const port = 2195;
> const gateway = (config.isProd) ? 'gateway.push.apple.com' :
> 'gateway.sandbox.push.apple.com';
>
> connection = tls.connect(port, gateway, tlsOptions, function () {
> if (!connection.authorized) {
> onConnectionError(self, connection.authorizationError);
> }
> else {
> ready = true;
> onConnection(self);
> handleDrain();
> }
> });
>
> This is my onError handler.
>
> connection.on('error', function (exception) {
> rejectMessages = true;
>
> if (!postDestroy){
> // tell the connection to close down
> connection.end();
>
> if (null !== cacheTimer){
> clearTimeout(cacheTimer);
> cacheTimer = null;
> }
>
> // start the destroy timer, which will destroy the
> connection, if it is not closed first
> destroyTimer = setTimeout(destroyConnection, 250);
>
> onConnectionError(self, exception);
> }
> else {
> console.error('Received an error after being destroyed
> %s', exception);
> onError(self, exception);
> }
> });
>
> Thanks for helping out.
Your snippet is incomplete so this may be irrelevant but one potential
issue is the scope of the `connection` variable:
> connection = tls.connect(port, gateway, tlsOptions, function () {
This reads as if it's declaring a global variable called `connection`.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en