APNS - Failed to send message

apple-push-notifications, ios, java, push-notification

Solution

I recommend Java PNS library: http://code.google.com/p/javapns/. I used it in one of my projects and it works fine.

Problem

I got strange problem with APNS. I using com.notnoop.apns library and when i try to push same message to 40 devices, i got ``` ApnsConnectionImpl : Failed to send message com.notnoop.apns.EnhancedApnsNotification@be443877... trying again java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(Unknown Source) ... ``` All going fine, when i try to push same message to 4, 10 even 15 devices. I try to split collection with push tokens from 40 to 4*10 and push this notification in foreach, but with second try i get same problem. This is code with push method: ``` //prepared collection and message private void sendMessage(Collection<String> ids, PayloadBuilder message) { try{ service.push(ids, message.build); }catch(Exception e) { logger.debug("APNS ERROR : size of collection - " + ids.size()); } ``` } Constructor of service: ``` try { service = APNS.newService() .withCert(pathToCertificate, certificatePasswd) .withProductionDestination() .build(); } catch(IOException e){ e.printStackTrace(); } ``` I lunch this method 10 times with different Collections of push tokens (collections got random from 1 to 40 tokens) and one time i got this exception (all of tokens was right). It is possible to get reset connection by APNS for no reason? If i lost connection, what suppose to do? Reconnect and try push one more time lost messages to devices? Please help, im out of ideas.

Original source