title: Sending a Keep-Alive packet manually using sockets
body: <p>I have a socket called "clientSock". It's connected and working.</p>
  
  <p>I receive data using a loop in a thread, as follows:</p>
  
  <pre><code>char[] inputChars = new char[1024];
  int charsRead = 0;
  
      while (!stopNow) {
  
          try {
  
              if ((charsRead =  inputStream.read(inputChars)) != -1)
                  {
  
                      System.out.println("Firing");
                      fire_dataRecieved(new String(inputChars, 0, charsRead)); //Fire event.
                  }
  
              } catch (IOException e) {
                  //CLIENT HAS DISCONNECTED...
                  connectedClient.disconnect();
                  stopNow();
              }
          }
  </code></pre>
  
  <p>I am thinking of sending a "keep alive packet"  by simply sending "#KEEP-ALIVE" to the other end. </p>
  
  <p>I can do this by using  <code>sendStream.print("#KEEP-ALIVE")</code>. Is there a better way of doing this? If not, is there an efficient way of checking if you got the packet? Or something already there that allows you to check if the other end is alive? <code>clientSock.setKeepAlive(true)</code> doesn't cut it for me. I need to check if the other end is alive on demand.</p>