I currently have an Apple Push Notification running on my server in Ruby. I'd like to get one going in Erlang as I'd like to use a supervisor to keep watch over it. Does anyone have any code that they could help me with?
Here's my Ruby code. One thing I do not like about this current implementation is that it does not seem to stay connected - it disconnects 2-3 times a day, and it seems after I reconnect that the first push will not go through:
context = OpenSSL::SSL::SSLContext.new
context.cert = OpenSSL::X509::Certificate.new(File.read(cert))
context.key = OpenSSL::PKey::RSA.new(File.read(cert))
def connect_sockets(server, context)
sock = TCPSocket.new(server, 2195)
ssl = OpenSSL::SSL::SSLSocket.new(sock,context)
ssl.connect
return sock, ssl
end
sock, ssl = connect_sockets(server, context) # this is called to initially connect and also reconnect whenever disconnected.
If Erlang Push isn't doable then I wouldn't mind sticking to my Ruby one as long as I can keep my connections alive, and perhaps supervise it through Erlang. Does anyone know if any of this is possible?
This question on Apple Push Notifications with Erlang might also be useful for this one.
The HTTP Client (with SSL support) that ships with Erlang works reasonably well ( I can't say I have battle tested it ). The relevant documentation is available here.
1) Don't forget to perform an "inets:start()" in your application before attempting to do HTTP calls.
2) In my (small) experience, starting the 'inets' module seems to be a bit tricky: don't try starting it within your supervisor module or else your servers won't work. I usually do 'inets:start()' in the first server module of my application before any other servers requiring HTTP are.
3) To perform the 'push' operation, I guess you would need to use the 'stream' option.
You might also check out the apn_on_rails project.
If you come up with an Erlang implementation, please consider sharing it with us :).
来源:https://stackoverflow.com/questions/1419187/apple-push-notification-in-erlang-or-improved-in-ruby