Implements the communication rules between the server and the client of the chat application.