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 / December 2005

Tip: Looking for answers? Try searching our database.

Server Conntion State Problem

Thread view: 
vidhi - 03 Dec 2005 11:03 GMT
We have a java game which runs with communication from a server and it
depends upon regular connectivity with the server. Our problem is in
connection discontinuation.

Firstly in between connection "Stream Corrupted Exception" arrives
and connection with server breaks (it's not lost actually but the ser
is go in a state where is neither send any thing nor receive but the
connection still not braked).

And Second one - some time without exception server just hangs up does
not listen and neither replies for some clients but same time work
properly for other

Here are some codes for data sending and receiving

at sending on server

public void sendMessage(CMessage cMessage)
{
    if(bIsClosed==false)
    {
         try
         {
           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 recive on client

public void run()
{
    Object objMessageRecived;
    CMessage cMessageRecived;
    while(true)
    {
        try
        {
            objMessageRecived=objInputStream.readObject();
            cMessageRecived=(CMessage)objMessageRecived;
            m_cWindow.handle_message(cMessageRecived);
        }catch(StreamCorruptedException sce){
            System.out.println("Error in connection !!!!!! "+sce.toString());
            break;
        }
        catch(IOException ex){
            System.out.println("Error in connection "+ex.toString());
            break;
        }
        catch(ClassNotFoundException ce){System.out.println("Error in
connection !!!!!! "+ce.toString());}
    }
}
Chris Smith - 03 Dec 2005 21:42 GMT
> Firstly in between connection "Stream Corrupted Exception" arrives
> and connection with server breaks (it's not lost actually but the ser
[quoted text clipped - 4 lines]
> not listen and neither replies for some clients but same time work
> properly for other

You haven't given nearly enough information to diagnose this problem.  A
good first step would be to post actual error messages.  A second step
would be to provide complete sample code to demonstrate the problem and
a set of steps needed to reproduce it.  Chances are that whatever is
wrong is buried in your very complex code somewhere, and we can't fix it
for you.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

vidhi - 05 Dec 2005 08:12 GMT
here is the code of class which is used as object for communication

package bin;
import java.util.Hashtable;
import java.io.Serializable;
import java.io.*;
public class CMessage implements Serializable
{
    private String m_strTitle;
    private int m_intAthleteId,m_intTrackId;
    private Hashtable m_hContentList;

    public CMessage()
    {
        m_strTitle="";
        m_hContentList=new Hashtable();
    }

    public CMessage(String strTitle)
    {
        m_strTitle=strTitle;
        m_hContentList=new Hashtable();
    }

    public CMessage(String strTitle,int intTrackId)
    {
        m_strTitle=strTitle;
        m_intTrackId=intTrackId;
        m_hContentList=new Hashtable();
    }

    public CMessage(String strTitle,int intTrackId,int intAthleteId)
    {
        m_strTitle=strTitle;
        m_intTrackId=intTrackId;
        m_intAthleteId=intAthleteId;
        m_hContentList=new Hashtable();
    }

    public void set_title(String strTitle)
    {
        m_strTitle=strTitle;
    }

    public String get_title()
    {
        return m_strTitle;
    }

    public void set_athlete_id(int intAthleteId)
    {
        m_intAthleteId=intAthleteId;
    }

    public int get_athlete_id()
    {
        return m_intAthleteId;
    }

    public void set_track_id(int intTrackId)
    {
        m_intTrackId=intTrackId;
    }

    public int get_track_id()
    {
        return m_intTrackId;
    }

    public void add_content(String strContent)
    {
        m_hContentList.put(new Integer(m_hContentList.size()+1),strContent);
    }

    public void add_content(Object objContent)
    {
        m_hContentList.put(new Integer(m_hContentList.size()+1),objContent);
    }

    public String get_content(int intContentIndex)
    {
        return (String)m_hContentList.get(new Integer(intContentIndex));
    }

    public Object get_content(Object objContentIndex)
    {
        return m_hContentList.get(objContentIndex);
    }

    public void clear()
    {
        m_strTitle="";
        m_hContentList.clear();
    }

    public int get_num_content()
    {
        return m_hContentList.size();
    }

    private void readObject(ObjectInputStream in)
   throws IOException, ClassNotFoundException {
       in.defaultReadObject();
   }

   // Does just default serialization
   private void writeObject(ObjectOutputStream out) throws IOException
{
       out.defaultWriteObject();
   }
}

the exception shows "java.io.StreamCorrutedException"


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.