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 / General / November 2005

Tip: Looking for answers? Try searching our database.

Stream Corrupted while connection

Thread view: 
vidhi - 26 Nov 2005 08:31 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:36 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.

see http://mindprod.com/jgloss/multiposting.html
Signature

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

John C. Bollinger - 26 Nov 2005 20:46 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?

Probably, if the issue is in your code rather than somewhere such as an
unreliable transmission medium.

> here is code at server for sending data

[...]

>           ObjectOutputStream objOutputStream=new
> ObjectOutputStream(socket.getOutputStream());
>         objOutputStream.writeObject(cMessage);
>         objOutputStream.flush();

[...]

> at receiving at client
>
> Object objMessageRecived;
> CMessage cMessageRecived;

[...]

>         objMessageRecived=(new
> ObjectInputStream(socket.getInputStream())).readObject();
>         cMessageRecived=(CMessage)objMessageRecived;
>         m_cWindow.handle_message(cMessageRecived);

[...]

The strangest thing I see there is that you are creating new Object
streams for each message send and reception.  It is unnecessary and
probably inefficient to do so; more importantly, it could be the source
of your problem.  I recommend that you create one Object stream on each
end and keep using it as long as the game is active.  You may still find
that you need an error recovery strategy, but it should be a fallback,
not something that gets exercised routinely.

If you continue having the same problem then we may need to see more
code to help you.  In that case, try also to figure out whether there is
anything systematic about the messages you are sending when the error
occurs.

Signature

John Bollinger
jobollin@indiana.edu

vidhi - 28 Nov 2005 07:37 GMT
Thanks for your attention
I will try to code as you suggested.
There is one more important thing I like to say is after happening this
exception connection is not beaked actually instead we are unable to
receive any message for server but can send as many as we can.


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.