Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / November 2005

Tip: Looking for answers? Try searching our database.

Stream Corrupted while connection

Thread view: 
vidhidwivedi@gmail.com - 26 Nov 2005 08:45 GMT
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.
Roedy Green - 26 Nov 2005 16:20 GMT
>Is there a way we can avoid this, so that connection will carry on till
>the game finish?
You can catch the exception and if game play is possible with out the
server carry on, or attempt to establish connection giving the server
some token to recognise the game to rejoin.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

vidhi - 28 Nov 2005 07:35 GMT
Thanks for your attention
Actually we cant effort to restart game because it is multiplayer one
and rejoining or restarting of game will effects others too,
There is one more important thing I like to say is after happening this
exception connection is not beaked instead we are unable to receive any
message for server but can send as many as we can.
Roedy Green - 28 Nov 2005 15:54 GMT
>There is one more important thing I like to say is after happening this
>exception connection is not beaked instead we are unable to receive any
>message for server but can send as many as we can.

What means this word "beaked"?

You mean you can't receive messages "from" the server, but you can
send?

Have you any evidence the server actually send them?
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

vidhi - 29 Nov 2005 08:25 GMT
you might be right

well your trick works the error never come again thanks.

but a new one "java.io.OptionalDataException" arrives, i am sick abt
this IOExceptions.

we have a larg program i passes all the big brakers eaisly but these r
too much.
Roedy Green - 29 Nov 2005 10:53 GMT
>but a new one "java.io.OptionalDataException" arrives, i am sick abt
>this IOExceptions.

the JavaDoc says Exception indicating the failure of an object read
operation due to unread primitive data, or the end of data belonging
to a serialized object in the stream. This exception may be thrown in
two cases:
An attempt was made to read an object when the next element in the
stream is primitive data. In this case, the OptionalDataException's
length field is set to the number of bytes of primitive data
immediately readable from the stream, and the eof field is set to
false.
An attempt was made to read past the end of data consumable by a
class-defined readObject or readExternal method. In this case, the
OptionalDataException's eof field is set to true, and the length field
is set to 0.

This basically means your read did not match your write.  
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.