title: java.io.StreamCorruptedException: invalid stream header: 00000000
body: <p>I'm trying to implement object serialization but stuck at the StreamCorruptedException.</p>
  
  <p>On the server's side:</p>
  
  <pre><code>public class MulticastServer {
                  public static void main(String[] args) throws java.io.IOException {
                  new MulticastServerThread().start();
                  }
  } 
  </code></pre>
  
  <p>Which calls:</p>
  
  <pre><code>public class MulticastServerThread extends QuoteServerThread {
                   boolean moreQuotes=true;
  public void run() {
    while (moreQuotes) {
    try {
      byte[] buf = new byte[256];
      String dString="Server";
      System.out.println(dString);
      buf = dString.getBytes();
  
      InetAddress group = InetAddress.getByName("230.0.0.1");
      DatagramPacket packet = new DatagramPacket(buf, buf.length,
                                                 group, 4446);
  
      socket.send(packet);
  
      ObjectInputStream is=null;
  
      ByteArrayInputStream byteStream = new ByteArrayInputStream(recvBuf);
      is = new ObjectInputStream(new BufferedInputStream(byteStream));
  
      Object o1=(Object)is.readObject();
      System.out.println(o1.a);
  
      is.close();
      socket.close();
      }}}}
  </code></pre>
  
  <p>And Object class on both server and client:</p>
  
  <pre><code>public class Object implements Serializable{
  private static final long serialVersionUID=1L;
  int a=10;
  }
  </code></pre>
  
  <p>And Client side code:</p>
  
  <pre><code>public class MulticastClient {
  public static void main(String[] args) throws IOException {
  MulticastSocket socket = new MulticastSocket(4446);
  InetAddress address = InetAddress.getByName("230.0.0.1");
  socket.joinGroup(address);
  
  Object o1=new Object();
  
  DatagramPacket packet;
  
  for (int i = 0; i &lt; 5; i++) {
    byte[] buf = new byte[256];
    packet = new DatagramPacket(buf, buf.length);
    socket.receive(packet);
  
    String received = new String(packet.getData());
    System.out.println("received data" +received);
  
    ObjectOutputStream os = null;
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream(15000);
              os = new ObjectOutputStream(new BufferedOutputStream(byteStream));
              os.flush();
              os.writeObject((Object)o1);
              System.out.println(o1.a);
              os.flush();
   }
   socket.leaveGroup(address);
   socket.close();
   }
   }
  </code></pre>
  
  <p>I've done all this:</p>
  
  <ol>
  <li>Put all classes under the same path on both machines</li>
  <li>attach breaks and try to find out where the problem is</li>
  </ol>
  
  <p>Can someone please help me? Thanks!</p>