APN Feedback service does not send tokens

I implemented a node.js script that queries the APN Feedback service to retrieve the list of invalid tokens. Unfortunately, I did not manage to get any invalid token. I followed these steps:

  1. Install the ios app with push notifications in sandbox mode.
  2. Send some notifications to the app (done successfully).
  3. Uninstall the app (I read that if the app that I uninstall is the only one with push notifications, it will cause the disconnection from the APN Service and make impossible to notify it that the app was uninstalled; but this is not my case, the iPad has many push notification apps installed!!).
  4. Send many other notifications with the same token, about ten or twenty, just to prove that the application token is not valid anymore (obviously the notifications are not delivered because the app has just been uninstalled).
  5. Query the Feedback service to finally get the invalid token. The Feedback service does not send anything, it just closes the connection without any kind of data.

This is the script I use to query the feedback service:

function pollAPNFeedback() {
    var certPem = fs.readFileSync('apns-prod-cert.pem', encoding='ascii');
    var keyPem = fs.readFileSync('apns-prod-key-noenc.pem', encoding='ascii');
    var options = { key: keyPem, cert: certPem };

    console.log("Connecting APN feedback service");

    var stream = tls.connect(2196, 'feedback.sandbox.push.apple.com', options, function() {
        if (stream.authorized == false) {
            return console.log('not connected')
        } else {
            console.log('connected');
        };


        var bufferlist = [];
        stream.on('data', function(data) {
            // APN feedback starts sending data immediately on successful connect
            console.log('-->Data: ', data);
            //bufferlist.push(data);
        });

        stream.on('readable', function(){
            console.log('we have incoming data');
        });

        stream.on('error', function(err){
            console.log('error: ', err);
        });

        stream.on('close', function(){
            console.log('closed');
            console.log('stream.data = ', stream.data);
        });
    });
}

As you can see, I put some listeners on the stream variable. The callback function on the 'data' listener is never invoked, only the 'close' event triggers its callback. I am sure that the connection is up because stream.authorized is true. What am I doing wrong?

Is it possible that you are using a production certificate to contact the sandbox environment?

From your code :

var certPem = fs.readFileSync('apns-prod-cert.pem', encoding='ascii');

var keyPem = fs.readFileSync('apns-prod-key-noenc.pem', encoding='ascii');

And :

var stream = tls.connect(2196, 'feedback.sandbox.push.apple.com', options, function()

If that's the case, that's why it doesn't work.