java.io.StreamCorruptedException
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;
publicclass 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();
}
}
publicclass LectureEntrantsimplements Runnable
{
publicvoid 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 ?

