开发者

Best way to receive new messages in a IM style app

开发者 https://www.devze.com 2023-01-28 08:52 出处:网络
At the moment I am just querying the server every 3 seconds to see if there are any new messages using an NSURLRequest and such. If there are it saves them to the database and sends an NSNotificationC

At the moment I am just querying the server every 3 seconds to see if there are any new messages using an NSURLRequest and such. If there are it saves them to the database and sends an NSNotificationCenter notification if there aren't then it just 开发者_运维问答waits 3 seconds and tries again.

Is this the best way to do it? I realise (form posts on here and information elsewhere) that opening a persistant connection to the server is tedius and not reccommended, so would this be the best way to do it?

My main worry is that if there are no new messages its downloading an empty (of information, but still a few bytes big) XML feed, and running this every 3 seconds is going to add up eventually and use a lot of data.

Any pointers would be much appreciated.

Thanks


XMPP would do this with a long-living TCP connection. How about using an XMPP service?


One of my own apps that I have written is an IM client and the app we develop at work also has IM features.

My own app uses a direct socket connection and TCP for communication. The TCP connection is kept alive with heart beat messages.

On the other hand, the app at work uses an XMPP based solution, which is fundamentally the same in that it uses a TCP or UDP connection, only instead of a proprietary protocol (in the case of my own IM app), XML messages are sent back and forth.

It depends how your server is currently implemented? Is this simply a chat implementation for your app only, or is it available to other users that may not be using an iPhone app? Would it be feasible for you to change the implementation on the server without breaking anything?


Are push notifications an options for your app?

0

精彩评论

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