1 Reply Latest reply: Jun 28, 2007 3:19 PM by 807605 RSS

    java.io.StreamCorruptedException

    807605
      Ok ,
      I did a little chat client/server software in java. In the last version i only used String. But now in version 2 I need to use Object (because with each message i need to send other info) but i always get the java.io.StreamCorruptedException But only on the client side! Here is a simplfy version of the my code (Throw the same exception ! )
      package ui;
      import object.*;
      import java.io.*;
      import java.net.*;
      
      
      
      import object.Message;
      public class Test {
           ObjectOutputStream oos;
           ObjectInputStream ois;
           public Test() {
                
                try {
                
                    Socket sock= new Socket("127.0.0.1",5050);
                     sock.setKeepAlive(true);
                     oos= new ObjectOutputStream(sock.getOutputStream());
                     oos.flush();
                              ois= new ObjectInputStream(sock.getInputStream());
                     Message m = new Message(2,"CONNECTION ESTABLISHED");
                     oos.writeObject(m);
                     oos.flush();
                     Thread threadLecture= new Thread(new LectureEntrants());
                     threadLecture.start();
      
                          
                } catch(Exception e1) {
                     e1.printStackTrace();
                }
           }
           public class LectureEntrants implements Runnable
           {
                
                public void run()
                {
                     Message m;
                     try
                     {
                          while((m=(Message)ois.readObject()) !=null)
                          {
                               
                          }
                     }catch (Exception e) {
                          e.printStackTrace();
                     }
                }
                     
           }
      }
      Error :
      java.io.StreamCorruptedException
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1332)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:348)
           at ui.Test$LectureEntrants.run(Test.java:39)
           at java.lang.Thread.run(Thread.java:595)
      Can anyone help me ?
        • 1. Re: java.io.StreamCorruptedException
          807605
          I found my problem... Finally!
          If anyone have the same problem here wath was my error :
          On the server side (Take me long to figured it was there since the error was throw on the client side) I had 2 instance of my ObjectOutputStream (don't ask me why !!!) I removed one and now everything is working fine !