Stream Corrupted while connection

V

vidhi

We have a java swing game that relies on connection with the server and
that is established through object stream. Our problem is that in
between game play "Stream Corrupted Exception" occurred and
connection breaks.
Is there a way we can avoid this, so that connection will carry on till
the game finish?

here is code at server for sending data

public void sendMessage(CMessage cMessage)
{
if(bIsClosed==false)
try
{
ObjectOutputStream objOutputStream=new
ObjectOutputStream(socket.getOutputStream());
objOutputStream.writeObject(cMessage);
objOutputStream.flush();
}catch(Exception e)
{
bIsClosed=true;
System.out.println("Error Sending Message
"+cMessage.get_title()+e.toString());
server.removeConnection( socket );
}
}



at receiving at client

Object objMessageRecived;
CMessage cMessageRecived;
while(true)
{
try
{
objMessageRecived=(new
ObjectInputStream(socket.getInputStream())).readObject();
cMessageRecived=(CMessage)objMessageRecived;
m_cWindow.handle_message(cMessageRecived);
}
catch(IOException ex){
System.out.println("Error in connection "+ex.toString());
break;
}
catch(ClassNotFoundException ce){System.out.println("Error in
connection !!!!!! "+ce.toString());}
}


Thanks for all your suggestions,
-Vidhi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,185
Latest member
GluceaReviews

Latest Threads

Top