Erlang 中的 Apple 推送通知(或 Ruby 中的改进?)
目前,我的服务器上有一个使用 Ruby 运行的 Apple 推送通知。我想在 Erlang 中使用一个,因为我想使用一个主管来监视它。有人有任何代码可以帮助我吗?
这是我的 Ruby 代码。我不喜欢当前实现的一件事是它似乎没有保持连接 - 它每天断开 2-3 次,并且在我重新连接后似乎第一次推送不会通过:
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.
如果 Erlang Push 不是如果可行,那么我不介意坚持使用我的 Ruby,只要我能保持我的连接活跃,也许还可以通过 Erlang 对其进行监督。有谁知道这是否可能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个有关使用 Erlang 的 Apple 推送通知的问题也可能有用对于这个。
This question on Apple Push Notifications with Erlang might also be useful for this one.
Erlang 附带的 HTTP 客户端(支持 SSL)工作得相当好(我不能说我已经对它进行了战斗测试)。相关文档可在此处获取。
1) 在尝试进行 HTTP 调用之前,不要忘记在应用程序中执行“inets:start()”。
2)根据我的(小)经验,启动“inets”模块似乎有点棘手:不要尝试在您的主管模块中启动它,否则您的服务器将无法工作。我通常在应用程序的第一个服务器模块中执行“inets:start()”,然后再执行任何其他需要 HTTP 的服务器。
3)要执行“推送”操作,我想您需要使用“流”选项。
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.
您还可以查看 apn_on_rails
项目。
如果您想出一个 Erlang 实现,请考虑与我们分享:)。
You might also check out the apn_on_rails
project.
If you come up with an Erlang implementation, please consider sharing it with us :).