Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to receive new messages in a IM style app

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

like image 339
Thomas Clayson Avatar asked Nov 29 '25 08:11

Thomas Clayson


2 Answers

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

like image 127
steveoh Avatar answered Nov 30 '25 20:11

steveoh


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?

like image 29
Jasarien Avatar answered Nov 30 '25 21:11

Jasarien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!