title: Proper Client <-> Server Communication
body: <p>Let's say I have a client and a server for a simple chatroom.</p>
  
  <p>They communicate through JSON strings.</p>
  
  <p>I understand the following example is unsafe, but I am only interested if this is an efficient way of communication.</p>
  
  <pre><code>// The Client connects to the server.
  // The Client sends a JSON string with the following variables to the server:
     --&gt; Intention: "Request"
     --&gt; Context: "Login"
     --&gt; Message: "username:admin|password:123"
  // The Server receives the JSON string and the string goes through an if-statement:
     --&gt; if(Intention.Equals("Request")){...}else if(Intention.Equals("Response")){...}
  // The Server now knows it's a Request and moves on to the next step.
     --&gt; if(Context.Equals("Login")){.&lt;check if user exists in server database and if the login details match&gt;.}
  // If the login details are correct, The Server marks the connected Client as logged in and sends a JSON string back to The Client:
     --&gt; Intention: "Response"
     --&gt; Context: "Login"
     --&gt; Message: "OK"
  // The Client receives the messages and sees it's OK, now the Client shows the user control panel and chatbox to the user which all send other Request JSON strings to The Server.
  // Any other context than "Login" check if the Client actually is marked as logged in, if not, the server returns a response with "ERR_NOT_LOGGED_IN"
  </code></pre>
  
  <p>Now I have a few questions:</p>
  
  <ol>
  <li>Would this be an efficient/good way of communicating back and forth between Client and Server? </li>
  <li>What is good/bad about it?</li>
  <li>Do you have any tips on how to make the communication better/more efficient (content-wise)?</li>
  <li>If this happened to be a big companies' chat server and passwords weren't stored in plain text but worked with private&amp;public keys, what else would be a big security flaw?</li>
  </ol>
  
  <p>I am asking, because I find a lot about good <em>ways</em> for Clients and Servers to communicate, but not about the actual <em>content</em> being sent back and forth.</p>
  
  <p>Thank you in advance!</p>