简体   繁体   English

简单的 iPhone 聊天应用

[英]Simple iPhone chat app

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

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.这是我的做法:我的后端会在ASP.NET,每次用户发送消息,它都会存储[message_id, from_id, to_id, message_content],然后接收方会有一个每5秒刷新一次的定时器来接来自 ASP.NET 服务器数据库的新消息。

But this raises a concern.但这引起了人们的担忧。 If I keep doing a refresh every 5 seconds, it will constantly stream and exhaust the receiver's bandwidth.如果我每 5 秒继续刷新一次,它将不断 stream 并耗尽接收器的带宽。 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谢谢

You won't just use bandwidth, you'll eat up battery power too.您不仅会使用带宽,还会消耗电池电量。 Use push notifications instead.请改用推送通知

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

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.而对服务器的简单 http 轮询可以小到一个二进制 package 并且不会显着影响用户的带宽。

Why don't you just use Apple's push notification system?为什么不直接使用 Apple 的推送通知系统? 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每当用户收到消息时,您的后端可以向 iphone 发送推送通知,并且 iphone 会在收到推送时下载新消息,或者如果消息不太长,您只需直接在推送通知中发送消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM