Andry
Andry

Reputation: 665

Apns: Connection closed by remote host

I have a Java app, which works with Apple Push Notification Server (APNS). I use lib: JavaPNS.jar for sendings push messages to iDevices. But, sometimes Push Notification doesn't work, I've found such error:

[16:35:40] Andrew Balakhanov: 2012-10-27 04:00:00,616 WARN [com.notnoop.apns.internal.ApnsConnectionImpl] Failed to send message com.notnoop.apns.EnhancedApnsNotification@af310b99... trying again java.net.SocketException: Connection closed by remote host at com.sun.net.ssl.internal.ssl.SSLSocketImpl.checkWrite(SSLSocketImpl.java:1339) at com.sun.net.ssl.internal.ssl.AppOutputStream.write(AppOutputStream.java:44) at java.io.OutputStream.write(OutputStream.java:58) 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.clinics.core.api.util.APN.sendReminderAlert(APN.java:55) at com.clinics.core.api.services.schedule.reminder.impl.ReminderSenderMobile.prepareAndSend(ReminderSenderMobile.java:190) at com.clinics.core.api.services.schedule.reminder.impl.ReminderSenderMobile.send(ReminderSenderMobile.java:132) at com.clinics.core.api.services.schedule.reminder.AbstractReminderFacade.generateAndSendReports(AbstractReminderFacade.java:53) at com.clinics.core.api.services.schedule.reminder.ReminderJob.doIt(ReminderJob.java:64) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:264) at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525)

Could you please tell me, what the error means? Is it mean, that Apple server banned me, is it mean that I send too many requests to it?

Upvotes: 1

Views: 7495

Answers (3)

mikeho
mikeho

Reputation: 7000

The problem I was facing was that the instructions I was using to generate my .p12 certificate file were incorrect. I ended up following the instructions from NWPusher and those worked for me.

Upvotes: 0

Ofra Yechiel
Ofra Yechiel

Reputation: 40

This error could also appear when the payload is too long.

You can check by calling PayloadBuilder's isTooLong() function.

PayloadBuilder payload = APNS.newPayload();

// build your payload               

if (payload.isTooLong())
{
    // your payload is too long, a push() will result in the above exception
}

Upvotes: 1

Age Mooij
Age Mooij

Reputation: 824

The most likely cause of this error is that you are sending production tokens to the sandbox server or sandbox tokens to the production server.

I got this exact behavior today until I figured out I had signed my app with an Ad Hoc profile, which makes the app use the production push server for generating the token, while my server was talking to the sandbox push server.

Upvotes: 9

Related Questions