简单的 iPhone 聊天应用程序

发布于 2024-11-15 06:25:26 字数 358 浏览 6 评论 0原文

我正在使用 Titanium 开发一个 iPhone 应用程序,其中有一个 iPhone 用户之间的小型聊天组件(不是短信,而是实际的客户端-服务器聊天)

这是我的方法:我的后端将在 ASP.NET 中,每次用户发送一条消息,它会存储[message_id, from_id, to_id, message_content],然后接收者将有一个计时器,每5秒刷新一次,以从ASP.NET服务器数据库中获取新消息。

但这引起了人们的担忧。如果我继续每 5 秒刷新一次,它将不断地传输并耗尽接收器的带宽。当有新消息时,是否有更好的方法来实现侦听器/接收器?

我听说过套接字编程,但是对于这种情况来说这是一个好方法吗?我该如何开始使用它?

谢谢

I am using Titanium to develop an iPhone application, in which has a small chat component between the iPhone users (not SMS, but actual client-server chat)

This is my approach: my back end will be in ASP.NET, every time a user sends a message, it will store [message_id, from_id, to_id, message_content], and then the receiver will have a timer that refreshs every 5 seconds to pick up new messages from the ASP.NET server database.

But this raises a concern. If I keep doing a refresh every 5 seconds, it will constantly stream and exhaust the receiver's bandwidth. Is there a better to way to implement a listener/receiver when there is a new message?

I have heard of socket programming but is it a good approach for this situation and how do i get started with it?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

暮年 2024-11-22 06:25:26

您不仅会使用带宽,还会消耗电池电量。请改用推送通知

You won't just use bandwidth, you'll eat up battery power too. Use push notifications instead.

岁月染过的梦 2024-11-22 06:25:26

建议仅在应用程序在后台运行时使用推送通知,而不是在用户实际聊天时使用推送通知。这就是推送通知最初设计的目的。

通过 http 轮询服务器是一个很好的解决方案,您可以使用一些节省带宽的技术,例如根据用户活动更新轮询频率(几分钟后没有聊天,将轮询时间减少到 30 秒)。

您不能在聊天应用程序中使用推送通知,因为您无法每分钟获取如此多的通知以使聊天看起来是实时的。对服务器的简单 http 轮询可以小到一个二进制包,并且不会显着影响用户的带宽。

It would be advisable to use push notifications only for when the application is running in background, not for when the user is actually chatting. That's what push notifications were designed for in the first place.

Polling the server via http is a good solution and there are techniques to save bandwith that you can use such as updating the frequency of the polling depending on user activity (no chats since a few minutes, reduce the polling time to 30 seconds).

You cannot use push notifications for a chat application because you cannot obtain so many notifications per minute to make the chat appear to be in real-time. And a simple http poll to a server can be as small as one binary package and not affect the user's bandwith significantly.

去了角落 2024-11-22 06:25:26

为什么不直接使用苹果的推送通知系统呢?
每当用户收到消息时,您的后端都可以向 iPhone 发送推送通知,iPhone 会在收到推送时下载新消息,或者如果消息不太长,则直接在推送通知中发送消息

Why don't you just use Apple's push notification system?
Whenever a user receives a message your back end can send a push notification to the iphone and the iphone either downloads new messages whenever it receives a push, or if the message isn't too long you just send the message directly in the push notification

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文