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.

On Jun 9, 12:25 am, Ben Noordhuis <[email protected]> wrote:
> On Sat, Jun 9, 2012 at 4:59 AM, catshow <[email protected]> wrote:
> > I am working on a new Apple Push Notification server using node.js.  I am
> > having issues with node not emitting the close event on a TLS SecureStream
> > after getting an EPIPE error event.  Has anyone else had this happen?  It
> > appears to happen after I do a lot of reconnects back to apple after
> > generating invalid device id's.  It does not happen each time.
>
> > How should I force it to close?  I am doing a hack that will schedule a
> > timer to fire 250 ms after the ERROR event and then call the
> > connection.destroy() method.  Is there a better way to handle this?
>
> Is node the TLS server or the client in your setup? Where do you see
> the EPIPE error event (net.Socket object, tls.SecurePair or
> tls.CleartextStream object, etc.)?

-- 
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

Reply via email to