APNS - Failed to send message
I'm having a strange problem with APNS. I am using com.notnoop.apns library and when I try to push the 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)
...
Everything goes well when I try to push the same message to 4, 10 even 15 devices.
I am trying to split a collection using push tokens from 40 to 4 * 10 and push that notification in foreach, but on second try I get the same problem.
This is the code with the 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());
}
}
Service constructor:
try {
service = APNS.newService()
.withCert(pathToCertificate, certificatePasswd)
.withProductionDestination()
.build();
} catch(IOException e){
e.printStackTrace();
}
I dine this method 10 times with different Collections of tokens (collections got random 1 to 40 tokens) and I got this exception one day (all tokens were correct). Can I get a connection reset over APNS for no reason? If I lose connection, what should I do? Connect and try to push again lost messages to devices? Please help, out of ideas.
source to share
I recommend the Java PNS library: http://code.google.com/p/javapns/ . I've used it in one of my projects and it works great.
source to share
You probably have invalid device tokens in your database.
Here are some similar questions that might help you:
Also, you should read this great article on Apple Push Notification Service issue .
source to share