开发者

Simple iPhone chat app

开发者 https://www.devze.com 2023-03-12 09:29 出处:网络
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)

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_c开发者_StackOverflow中文版ontent], 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


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).

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消