title: Worklight Push exception: SocketException: Connection closed by remote host
body: <p>I did all steps of Push and now when calling Push its giving following exception.</p>
  
  <p>I am calling IBM's sample Push code. I can see in the DB that device ID, Token, user ID are there as user has successfully subscribed for Push.</p>
  
  <pre><code>[4/10/13 18:27:24:647 AST] 00000044 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log Push Called -----&gt; userId:aahad notificationText:ThisismyPushMessage
  [4/10/13 18:27:24:663 AST] 00000044 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log submitNotification &gt;&gt; userId :: aahad, text :: ThisismyPushMessage
  [4/10/13 18:27:24:679 AST] 00000045 ApnsConnectio W com.notnoop.apns.internal.ApnsConnectionImpl sendMessage Failed to send message com.notnoop.apns.EnhancedApnsNotification@6acb1af9... trying again
                                   java.net.SocketException: Connection closed by remote host
      at com.ibm.jsse2.SSLSocketImpl.k(SSLSocketImpl.java:165)
      at com.ibm.jsse2.k.write(k.java:30)
      at java.io.OutputStream.write(OutputStream.java:69)
      at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:161)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
      at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
      at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
      at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
      at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
      at java.util.concurrent.FutureTask.run(FutureTask.java:149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
  </code></pre>
  
  <p>From WL server machine I can telnet Apple servers.</p>
  
  <p>Is there any other thing that I have to check on my network? as my client has very strict securities.</p>
  
  <p>This is Push adapter function code I am using.</p>
  
  <pre><code>function testNotification(userId ,notificationText){
      WL.Logger.debug("Push Called -----&gt; userId:" + userId + " notificationText:"+notificationText);
      var userSubscription = 
          WL.Server.getUserNotificationSubscription('PushAdapter.PushEventSource', userId);
  
      if (userSubscription==null){
          return { result: "No subscription found for user :: " + userId };
      }
  
      WL.Logger.debug("submitNotification &gt;&gt; userId :: " + userId + ", text :: " + notificationText);
  
      WL.Server.notifyAllDevices(userSubscription, {
          badge: 1,
          sound: "sound.mp3",
          activateButtonLabel: "ClickMe",
          alert: notificationText,
          payload: {
              foo : 'bar'
          }
      });
  
      return { result: "Notification sent to user :: " + userId };
  }
  </code></pre>
  
  <p><strong>I have narrowed down this problem.</strong></p>
  
  <p>I did Push demo on my local machine (windows 7 lenovo laptop)  WL Consumer studio using jetty and it worked fine. I received notifications.</p>
  
  <p>I figured out that i am doing one mistake that is I am using Development APNS certificate with distribution profile....that means WL server would be sending request to wrong  Apple server.</p>
  
  <p>I tried above thing on my laptop to test Push demo, plus I also stopped my firewall &amp; Norton antivirus on my personal laptop, in this way Push worked fine.</p>
  
  <p>Now today at client end, I re-generated another APNS certificate that is Production APNS and using distribution profile I am trying to achieve this. This time I am receiving different exception.  </p>
  
  <pre><code>[4/11/13 12:36:32:566 AST] 00000046 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log Push Called -----&gt; userId:aahad notificationText:This is my First Push Message
  [4/11/13 12:36:32:566 AST] 00000046 JavaScriptInt I com.worklight.integration.js.JavaScriptIntegrationLibraryImplementation log submitNotification &gt;&gt; userId :: aahad, text :: This is my First Push Message
  [4/11/13 12:36:32:676 AST] 0000003b webcontainer  E com.ibm.ws.webcontainer.internal.WebContainer handleRequest SRVE0255E: A WebGroup/Virtual Host to handle /favicon.ico has not been defined.
  [4/11/13 12:36:58:066 AST] 00000045 ApnsConnectio E com.notnoop.apns.internal.ApnsConnectionImpl socket Couldn't connect to APNS server
                                   java.net.ConnectException: Connection timed out: connect
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
      at java.net.Socket.connect(Socket.java:539)
      at com.ibm.jsse2.SSLSocketImpl.connect(SSLSocketImpl.java:284)
      at com.ibm.jsse2.SSLSocketImpl.&lt;init&gt;(SSLSocketImpl.java:712)
      at com.ibm.jsse2.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:15)
      at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:133)
      at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:160)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
      at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
      at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
      at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
      at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
      at java.util.concurrent.FutureTask.run(FutureTask.java:149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
      at java.lang.Thread.run(Thread.java:772)
  
  [4/11/13 12:36:58:066 AST] 00000045 ApnsConnectio W com.notnoop.apns.internal.ApnsConnectionImpl sendMessage Failed to send message com.notnoop.apns.EnhancedApnsNotification@4fc0c1a1... trying again
                                   com.notnoop.exceptions.NetworkIOException: java.net.ConnectException: Connection timed out: connect
      at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:146)
      at com.notnoop.apns.internal.ApnsConnectionImpl.sendMessage(ApnsConnectionImpl.java:160)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:46)
      at com.notnoop.apns.internal.AbstractApnsService.push(AbstractApnsService.java:52)
      at com.notnoop.apns.internal.ApnsServiceImpl.push(ApnsServiceImpl.java:36)
      at com.worklight.integration.notification.apns.ApplicationConnection.sendNotification(ApplicationConnection.java:84)
      at com.worklight.integration.notification.apns.APNSMediator.sendNotification(APNSMediator.java:85)
      at com.worklight.integration.notification.Mediator$4.run(Mediator.java:174)
      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:452)
      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
      at java.util.concurrent.FutureTask.run(FutureTask.java:149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:897)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:919)
      at java.lang.Thread.run(Thread.java:772)
  Caused by: java.net.ConnectException: Connection timed out: connect
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
      at java.net.Socket.connect(Socket.java:539)
      at com.ibm.jsse2.SSLSocketImpl.connect(SSLSocketImpl.java:284)
      at com.ibm.jsse2.SSLSocketImpl.&lt;init&gt;(SSLSocketImpl.java:712)
      at com.ibm.jsse2.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:15)
      at com.notnoop.apns.internal.ApnsConnectionImpl.socket(ApnsConnectionImpl.java:133)
      ... 13 more
  </code></pre>
  
  <p>Now here are two things we have to understand, help in this please.</p>
  
  <p><strong>(1)</strong> By looking at Logs , does it still means there is network blockage somewhere at client side?</p>
  
  <p><strong>(2)</strong> I am seeing one difference in Keychain when it is showing both Development APNS &amp; Production APNS certificates. Both are using same private key. The development apns certificate shows App ID "us.com.abc.myApp" as Post-fix to it.....While the Production apns certificate is NOT showing it. ........ <strong>Is this fine? Or will it cause some problem</strong> ?....... I tried re-generating Production APNS certificates three times but each time it is showing same number and not APP ID as Post-fix.</p>
  
  <p><strong>Thanks</strong></p>