title: Writing a 2-byte integer to a stream?
body: <p>I'm trying to interact with an application over the network which uses a simple protocol. I have to send a header that looks like this:</p>
  
  <p><strong>2 bytes</strong> = Data Length (including Request Type)<br>
  <strong>1 byte</strong> = Request Type</p>
  
  <p>I'm taking both parameters as integers:</p>
  
  <pre><code>private static void WriteHeader(Stream buf, int length, int requestType) {
      buf.Write(BitConverter.GetBytes(length), 0, 2);
      buf.WriteByte((byte)requestType);
  }
  </code></pre>
  
  <p>I'm calling it like this:</p>
  
  <pre><code>byte[] outBuf = new byte[256];
  using (MemoryStream outStream = new MemoryStream(outBuf)) {
      // Socket connection stuff here
      WriteHeader(outStream, 1, 110);
      sock.Send(outBuf);
      // Receive stuff here, never returns
  }
  </code></pre>
  
  <p>I don't get any kind of exception when calling this method or sending <code>outBuf</code> over a socket, but the network application never responds. I can query it with other programs, though, so I'm fairly certain that it's because my header isn't being written correctly.</p>
  
  <p>Am I doing something wrong when writing the values?</p>
  
  <p><strong>EDIT:</strong> Added MemoryStream code</p>