title: I'm trying to use Apns library for node.js and get an error - "TypeError: Cannot read property 'bufferSize' of undefined"
body: <p>On Ubuntu Linux I am running node.js 0.12.7 and I have installed npm package "apns". I wish to send push notifications to apple devices and later on to Android and Windows.</p>
  
  <p>I have very basic code but am still running into issues. The script throws following run time error:</p>
  
  <pre><code>  pankaj@pankaj-Ubuntu-asus:~/nodeServer/testCode$ node testPushDirectToApple.js
    [Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] Send : 6840038dee0ac6aa3c4a5210746961e80ed9797410a5100f8835b8dfbb
  [Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] open socket
  [Wed Sep 09 2015 02:32:12 GMT-0400 (EDT)] drain
   /home/pankaj/node_modules/apns/lib/connection.js:193
    if(this.tlsConnection &amp;&amp; this.tlsConnection.socket.bufferSize !== 0)
                                                   ^
   TypeError: Cannot read property 'bufferSize' of undefined
      at Connection.drain (/home/pankaj/node_modules/apns/lib    /connection.js:193:54)
      at TLSSocket.&lt;anonymous&gt; (/home/pankaj/node_modules/apns/lib/connection.js:171:12)
      at TLSSocket.g (events.js:199:16)
      at TLSSocket.emit (events.js:104:17)
      at TLSSocket.&lt;anonymous&gt; (_tls_wrap.js:950:16)
      at TLSSocket.emit (events.js:104:17)
      at TLSSocket._finishInit (_tls_wrap.js:460:8)
  </code></pre>
  
  <p>Here is my code: "testPushDirectToApple.js"</p>
  
  <pre><code> var apns = require("apns"), notification, options, connection;
  
     options = {
         keyFile : "privateKey_key.pem",
         certFile : "aps_development_cert.pem",
         passphrase: "&lt;scrubbed&gt;",
         gateway: "gateway.sandbox.push.apple.com",
         port: 2195,
         debug : true
      };
  
   function pushviaDirectConenction(deviceToken, message){
  
    connection = new apns.Connection(options);
  
    notification = new apns.Notification();
    notification.alert = message;
    notification.device = new apns.Device(deviceToken);
  
    connection.sendNotification(notification);
  }
  
    pushviaDirectConenction("68c2440038dee0ac6aa3c4a5210746961e80ed9797410a5100f8835b8d", "Hi there");
  </code></pre>
  
  <p>Please advice how to resolve this.</p>
  
  <p>Thanks in advance.</p>