Apple Push Notification in Erlang (or improved in Ruby?)

让人想犯罪 __ 提交于 2019-12-06 05:44:48

问题


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?


回答1:


This question on Apple Push Notifications with Erlang might also be useful for this one.




回答2:


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.




回答3:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!