LonestarX
LonestarX

Reputation: 41

iOS messaging system (chat system) in app

So I have my iOS App (it's a social networking one) and I would like to add a messaging and chat system. I've looked up ways to do this but haven't found one that I could either fully understand or implement as most were too complicated for what I want.

I have a "friend list" view controller and when touched in one of the names in the list , a "messages" view controller (just like any im window) goes in where you can chat with the selected friend.

The ways I found to do this were either XMPP or "a TCP connection". I tried understanding XMPP but for XMPP you need "logging in" etc, and that would require an extra id or something which would complicate things. I already have my in app users ID – I don't want a second one just for chat.

The second method – making a TCP connection and sending messages via that connection – I could not fully understand nor find examples of it implemented.

Upvotes: 4

Views: 1508

Answers (2)

Suhas_Patil
Suhas_Patil

Reputation: 13

You can check out this link in which XAMPP framework is used...

https://github.com/KanybekMomukeyev/FacebookChat

Upvotes: 0

paulmelnikow
paulmelnikow

Reputation: 17208

The most difficult part of a simple chat protocol is a fast way to notify the client that a message has been received. To do this with REST or HTTP for example requires the client poll the server every few seconds, which is inefficient and impractical if your app needs to scale.

XMPP certainly adds extra work. Your client will need to make a separate connection to the XMPP server, and you'll have to find a way to integrate authentication. But as long as the client has a connection open, it'll be notified the moment a message arrives.

While chat isn't the same as publish–subscribe, they share the same design challenge, which is how to notify the client when a message is received without the client having to poll. While researching choices for a publish–subscribe application I came upon a helpful chart comparing XMPP, RSS, and other options. The same site offers a good explanation of polling. Again, it's not about chat, but you can still use it to understand the problem.

As you mention, another option a TCP connection which is kept alive, on which the server can place responses when they arrive. You can even do that over HTTP if you want. I'm not aware of any servers which do this right out of the box. (For my needs I selected XMPP and XMPPFramework.)

Upvotes: 2

Related Questions