title: Simple Java TCP socket protocols
body: <p>I'm trying to find a reliable way to send control messages that obey a defined protocol in order to tell the server what kind of data he will receive. For example, I want to send a pure text message to invoke a remote method:</p>
  
  <pre><code>#METHOD1#CLOSE#
  </code></pre>
  
  <p>or I want to send a serialized object to the server:</p>
  
  <pre><code>#OBJECT# .......here comes the serialized object data....#CLOSE#
  </code></pre>
  
  <p>So basically I just want to send string control messages that are completely independent 
  of the stream content that follows.</p>
  
  <p>By wrapping an input stream into a Scanner object I'm able to extract strings from the input stream, but if this stream is a serialized object then the object can't be restored afterwards. Thanks for any help.</p>