title: C# equivalent of Java's DataOutputStream?
body: <p>I've done quite a bit of research on the topic and I see that this question is asked quite often, but none of them have the answer that I'm looking for, the most common solution was to use the <strong>BinaryWriter</strong> class that comes with C#, however it doesn't seem to be doing it's job.</p>
  
  <p>For my Server Application I'm using <strong>Netty</strong> a Java Based NIO Networking Library which makes use of DataInput and DataOutput Streams. I have a client that works in java, but it was just for testing purposes and I'm now in the progress of moving it over to C# to put it into my game.</p>
  
  <p>Here's the C# Code in its basic format, just trying to get things working for the time being..</p>
  
  <pre><code>Client = new TcpClient ();
  try 
  {
      Client.Connect (IPAddress.Parse ("127.0.0.1"), PORT);
      Stream = Client.GetStream();
      ClientOutput = new BinaryWriter(Stream);
      ClientInput = new BinaryReader(Stream);
  
      ClientOutput.Write ((string) "UserIsBob");
      ClientOutput.Write ((string) "MyPassLol");
      ClientOutput.Flush();
  
  } 
  </code></pre>
  
  <p>Now, this looks fine; but here's the problem, when using</p>
  
  <pre><code>DataInputStream.readUTF()
  </code></pre>
  
  <p>On the Java server, nothing happens; However if I use </p>
  
  <pre><code>DataOutputStream.writeUTF(String)
  </code></pre>
  
  <p>From the java client, the server will read it perfectly fine and print it to the console.</p>
  
  <p>I'm really not sure what I'm doing wrong, but there doesn't seem to be much information on it. The functionality that I require is the following:</p>
  
  <ul>
  <li>WriteByte(byte)</li>
  <li>WriteBytes(byte[])</li>
  <li>WriteUTF(String)</li>
  <li>WriteInt(int)</li>
  <li>WriteLong(long)</li>
  <li>WriteFloat(float)</li>
  <li>WriteDouble(double)</li>
  <li>WriteBoolean(boolean)</li>
  </ul>
  
  <p>From my understanding you can do all of this in the <strong>BinaryWriter</strong> class by just typecasting, <strong>but it doesn't seem to be picked up by the Java DataInputStream</strong></p>
  
  <p>After reading the documentary posted by nodakai, I came up with this code:</p>
  
  <pre><code>void WriteUTF(string utf) 
  {
      short buffer = (short)System.Text.ASCIIEncoding.ASCII.GetByteCount(utf);
      ClientOutput.Write ((short)buffer);
      ClientOutput.Write ((string)utf);
  }
  </code></pre>
  
  <p>However, it still doesn't work. </p>
  
  <p>I did a little more looking into it and found that if I used <strong>InputStream.ReadShort()</strong> that I could get the value sent, so the String with the value of "Hello World" would be send like this </p>
  
  <pre><code>WriteShort(11)
  WriteString("Hello World")
  Flush()
  </code></pre>
  
  <p>However, when doing the equivalent in C#, it still doesn't come through, even though it's read on the java side the same way. </p>