I am working on a simple web server that sends push notification to my iPhone app. I've tried using existing Python packages, but they all suffer from this problem:
When an invalid token is sent, Apple will send back a error message and close the socket. I need to send a large number of push notifications, but if one of them has an invalid token, the rest won't be delivered to Apple.
So currently, my code looks something like this:
for m in messages:
socket.send(m)
But when the first of the messages has invalid token, so Apple closes the socket as soon as it receives the first message, socket still sends all the messages without any error.
I can't afford to do a recv
after each message with a timeout, since that will take too long. What can I do to know when the socket is closed and open a new one?