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 ?

[3080 byte] By [bobinoa] at [2007-11-27 9:10:22]
# 1

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 !

bobinoa at 2007-7-12 21:51:48 > top of Java-index,Java Essentials,Java Programming...