title: how to do multiple stream.writes and reads on a single socket
body: <p>My application connects to a device and sends multiple commands across a single socket connection. It then reads the response to these the basic structure is </p>
  
  <p>command 1</p>
  
  <p>stream.write</p>
  
  <p>stream.read</p>
  
  <p>command 2</p>
  
  <p>stream.write</p>
  
  <p>stream.read</p>
  
  <p>.
  .
  .</p>
  
  <p>i am wondering if there is a better way of doing this. I am not worried about blocking because this is running on a different thread than the rest of the program. the problem i am encountering is that sometimes the data for command 1 lands in the read for command 2. The other thing is the 1st byte that i receive is unique to the command.</p>
  
  <p>any help would be appreciated</p>