什么会导致与 APNS 的连接间歇性断开?
我有一个 ruby 脚本,可以打开与 Apple 推送服务器的连接并发送所有待处理的通知。我看不出任何原因,但当 Apple 断开我的脚本时,我收到了损坏的管道错误。我已经编写了脚本来适应这种情况的发生,但我宁愿找出它发生的原因,这样我就可以首先避免它。
它不会始终在收到特定通知时断开连接。它不会在特定字节传输大小时断开连接。一切似乎都是零星的。在单个连接上可以发送的数据传输或有效负载数量是否有某些限制?看到人们的解决方案始终保持一个连接打开,我认为这不是问题。我看到连接在 3 个通知后断开,我也看到连接在 14 个通知后断开。我从来没有见过它超过 14。
有其他人遇到过这种类型的问题吗?这该如何处理呢?
I've got a ruby script that opens a connection to Apple's push server and sends all the pending notifications. I can't see any reason why, but I get broken pipe errors when Apple disconnects my script. I've written my script to accomodate this happening, but I would rather just find out why it's happening so I can avoid it in the first place.
It doesn't consistently disconnect on a specific notification. It doesn't disconnect at a certain byte transfer size. Everything appears to be sporadic. Are there certain limitations to the data transfer or payload count you can send on a single connection? Seeing people's solutions that hold one connection open all the time, I would assume that isn't the issue. I've seen the connection drop after 3 notifications, and I've seen it drop after 14 notifications. I've never seen it make it past 14.
Has anyone else experienced this type of problem? How can this be handled?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该问题是由于向 APNS 服务器发送无效的设备令牌引起的。在这个具体案例中,它是一个开发代币。当无效的设备令牌发送到 APNS 时,它会断开套接字。这可能会引起一些麻烦,Apple 已将其解决为他们将在未来的更新中解决的问题。
The problem was caused by sending an invalid device token to the APNS server. In this specific case it was a development token. When an invalid device token is sent to APNS, it disconnects the socket. This can cause some headaches, and has been addressed by Apple as being something they are going to address in future updates.
我也遇到过同样的问题,做了两件事来解决它:
这是我当前的连接代码,使用 EventMachine:
end
它使用通知中的 ID 字段将
连接中的写入和读取分开,以将我发送的通知与收到的反馈相关联。
I had the same issue for a bit and did two things to tackle it:
Here's my current connection code, using EventMachine:
end
end
It separates writes and reads in the connection, using the ID field in the notification to correlated notifications I send with feedback I receive.