title: "StreamCorruptedException: invalid stream header" when reading ObjectInputStream sent from C# client
body: <p><strong>Problem</strong></p>
  
  <p>I'm trying to send a protobuf message from a C# client to this Java Server but I get this exception:</p>
  
  <pre class="lang-none prettyprint-override"><code>java.io.StreamCorruptedException: invalid stream header: 0A290A08 
  java.io.StreamCorruptedException: invalid stream header: 0A290A08
      at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
      at java.io.ObjectInputStream.&lt;init&gt;(Unknown Source)
  </code></pre>
  
  <p>I'm a bit at a loss to be honest. Any help is appreciated. Thanks!</p>
  
  <ul>
  <li><strong>Java server</strong></li>
  </ul>
  
  <pre class="lang-java prettyprint-override"><code>    public ControllerThread(Socket s){
      this.s = s; try {
  
          this.objectInputStream = new ObjectInputStream(s.getInputStream());
          byte size = objectInputStream.readByte();System.out.println("Server: BYTES SIZE:" +     size);
          byte[] bytes = new byte[size];
          objectInputStream.readFully(bytes);
          AddressBook adb = AddressBook.parseFrom(bytes);
          System.out.println("Server: Addressbook:" + adb.getPersonCount());
  
      } catch (IOException e) { 
          System.out.println("Server: BufferedReader oder PrintWriter von ThermoClient konnte nicht erstellt werden");
          e.printStackTrace(); } 
          } }
  </code></pre>
  
  <p><strong>C# code</strong></p>
  
  <pre><code>public AddressBook InitializeAdressBook()
  {
      Person newContact = new Person();
  
      AddressBook addressBookBuilder = new AddressBook();
      Person john = new Person();
      //john.id=1234;
      john.name="John Doe";
      john.email="jdoe@example.com";
      Person.PhoneNumber nr = new Person.PhoneNumber();
      nr.number="5554321";
      john.phone.Add(nr);
      addressBookBuilder.person.Add(john);
      TextBox.Text += ("Client: Initialisiert? " + addressBookBuilder.ToString()) + "\t" + "\n";
      TextBox.Text += " Erster Person " + addressBookBuilder.person.First().name + "\t" + "\n";
  
      return addressBookBuilder; 
  }
  </code></pre>
  
  <p><strong>c# OutputStream</strong></p>
  
  <pre><code>    public void SendMessage(Stream ns, byte[] msg)
      {
          byte size = (byte)msg.Length;
  
          try
          {
              ns.WriteByte(size);
              ns.Write(msg, 0, msg.Length);
              ns.Flush();
              ns.Close();
          }
          catch (ArgumentNullException ane)
          {
              TextBox.Text += "ArgumentNullException : {0}" + ane.ToString();
          }
          catch (Exception e)
          {
              TextBox.Text += ("Unexpected exception : {0}" + e.ToString());
          }
  
  
      }
  </code></pre>