4

I was tasked to create a Chat function for our app in iOS. I found this tutorial which creates a Chat app from scratch.

http://www.ibm.com/developerworks/library/x-ioschat/index.html

The link above is very helpful, but there is a small problem. In the app, a request will be made every 5 seconds to look for new responses. One of my colleagues said that it is not advisable to make a request to the server every now and then.

So I decided to look for other alternatives. I learned about long-polling through this link.

From what I understood, once a request was made the server will "hold" the request until something interesting comes up. Does this mean that once a response was thrown to the user, the request ends? If that's true, this means that a request will be made every now and then as well, right?

If that's the case, can anyone tell me what's the best way to implement a chat function in iOS?

My friend showed me a AJAX JavaScript code (I just found out that he also used a plug-in, which I am not familiar with) where a single continuous request was made, and this request doesn't end even if a response was already thrown to the user. Is there a way to do this in iOS?

Community
  • 1
  • 1
Anna Fortuna
  • 1,071
  • 2
  • 17
  • 33
  • My friend showed me an AJAX code where a single continuous request was made, and this request doesn't end even if a response was already thrown to the user. Is there a way to do this in iOS? it is possible. show us the code, there might be something special? – Abby Chau Yu Hoi Sep 21 '12 at 02:28
  • Alright, but he's not yet around so I'll show it later. – Anna Fortuna Sep 21 '12 at 02:34
  • One more thing, the problem in iOS is that requests had time-outs. That's why I thought it was impossible to perform one continuous request in iOS. Hopefully I'm wrong. – Anna Fortuna Sep 21 '12 at 02:36

1 Answers1

1

It is not a good approach to make http ajax request to send and receive chat. A chat response should be displayed at the moment when the other user press "Send". We cant ask for the users to wait 1 second to fetch if there any new responses.

You must use a chat server to accomplish this. I hope the following url would be helpful. I just wanted to give you the Idea of using a Chat Server.

http://wiki.remobjects.com/wiki/SuperHTTP_Chat_(iOS)Sample(Xcode)

Shakeel
  • 574
  • 1
  • 5
  • 16