I am trying to implement support for Apple's advanced push notification message format in my Rail app, and some I'm facing disappointing problems. I could not clearly understand the bases as I thought.
My main problem is that if I send all the messages correctly, my code is hanging because the socket. If your message looks fine, the apple does not return anything , so my program locks.
Here are some pseudocodes that I have to work on:
cert = file.read (options [: cert]) ctx = OpenSSL :: SSL :: SSLContext .new ctx.key = OpenSSL :: PKey :: RSA.new (cert, options [: passphrase]) ctx standard = openSSL :: X509 :: certificate.new (cert) sok = tcpsetset New (option [: Host], Option [: Port]) SSL = OpenSSL :: SSL :: SSLNet.net (ASOC, CTX) SSL. Sync = true ssl.connect messages.each do | Message | Ssl.write (message.to_apn) end if read_buffer = ssl.read (6) process_error_response (read_buffer) termination Obviously, there are several problems with this:
- If I send a message to a large number of devices, and the failure message is sent halfway through processing, then I do not really see the error unless I already tried to send it to everyone According to the device.
- As mentioned earlier, if all messages were acceptable to Apple, then my app socket would be hanging on the read call. In a way I have tried to solve this is to read from a socket in a separate thread:
thread.nu () {data = Ssl.read (6) end of process_error_response (data) messages.each do | Message | Ssl.write (message.to_apn) end ssl.close sock.closeThis does not seem to work. The data is never being read from the socket. This is probably a misconception about which sockets are expected to work.
I have called a non-blocking reading that I thought ... but Ruby does not seem to have it unblocked blocking 1.9 calls to SSLSocket ... which I unfortunately do not use anymore can do.
Can someone point me in the right direction, with a better understanding of socket programming?
Cam is correct: the traditional way of handling this situation is IO.select .select ([ssl], zero, zero, 5) read_buffer = ssl.read (6) process_error_response (read_buffer) If it is readable or and zero otherwise it will be ssl for "publicability" for 5 seconds.
Comments
Post a Comment