I would like to write a simple chat for android to practice. In my understanding, the principle of the chat is: There is a database where users are registered. One user chooses the second (who wants to send a message) and writes a message. It is sent to the server, the server is checked by the second user online or not. If it is online, then sends a message to it, otherwise it stores on the server until the user enters.
Please tell me where to start, what to write on the server part, the chat algorithm is about the right?