Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

What is needed to make something like this?

I was thinking and wondering about what you need to know to build something like a messenger app for ex. iPhone and how does a messenger work. How is the connections to the server made? How will the receiver know that a message is sent to him/here? Does the app check for messages every second or so, or what's the deal here?

1 Answer

Sante Kotturi
Sante Kotturi
7,434 Points

While I'm pretty new to web and mobile development (and not knowing the inner secrets of iMessaging, FB Messenger or Google Hangouts), I believe these technologies would help get an idea of what's being done:

  1. Is the app checking every second? I believe they probably use something like socket.io: http://socket.io/ It basically keeps an open connection between the two which allows for those 3 bouncing dots letting you know when the other user is typing... (and then really fast sending of the message)

  2. How will the receiver know the message is delivered? A callback function would be perfect here. Basically user1 sends the message to user2 along with a function specifying what do when user2 receives the message. When the message is received by user2, the callback function is fired which sends a message back to user1 saying user2 received the message. Something pseudocode like:

user1.submit(message, recipient, function(){
      recipient.sendMessage(message, function(status){
        print(status); 
     }); 
}); 

then on the other end:

user2.receive(message, sender, function(callback){
      read(message); 
      callback("got the message");      // this is what gets send back as the "status"
}); 

There's a lot of documentation and tutorials to better understand the callback function but I believe its what you would want to use.

Hope that at least helps get you in the right direction!

Thanks for all the info! Post it as an answer and I'll give you my thumbs up ;)