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.
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.