I have a design question. Let us say you were tasked with building a chat application, specifically for iOS (iOS Chat Application). For simplicity let us say you can only chat with one person at a time (no group chat functionality).
How then can you achieve sending a message directly to an end user from phone A to phone B?
Obviously there is a web service layer with some API calls. One of the API calls available will be
startChat(). After starting a chat, when you send a message, you make another async call, let us call it
sendMessage() and pass in a string with your message. Once it goes to the web service layer, the message gets stored in a database.
Here is where I am currently stuck. After the message gets sent to the web service layer, how do we then achieve sending/relaying the message over to the end user? Should the web server send out a message to the end user and notify them, or should each client call a
receiveMessage() method periodically, and if the server side has some info for them it can then respond with that info?
Finally, how can we handle the case in which the user you are trying to send a message to is offline? How can we make sure the end user gets the packet when he moves back to an area with signal?