AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Socket failure following writeObject

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
maestroff
Guest





PostPosted: Wed Jul 20, 2005 5:38 pm    Post subject: Socket failure following writeObject Reply with quote



I have a test program I've been working on to experiment with socket
communication. Well actualy 2 programs - 1 client & 1 server program.
Currently the client can request 2 things to be sent from the server
and displayed by the client. First is a simple java.util.Date object
that contains the server's current date-time. That works fine. But then
I tried to request a complex object I wrote. It contains several
private variables, a public enumeration variable, and an inner class
with its own private variables. Both the outer and inner classes
implement Serializable.

The problem is that while I can get and use the object fine the first
time the client sends the request, on any subsequent try I get an
IOException with a message of null. This is true even if a request for
the object is followed by the simpler Datetime request. As soon as the
one object request is done, all further communication causes
IOExceptions.

When the client program is started it creates these connections:

try
{
socket = new Socket(HOST_NAME, SOCK_PORT);
outStream = new PrintWriter(socket.getOutputStream(), true);
inStream = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
objectInStream = new
ObjectInputStream(socket.getInputStream());
}

When I click a button on the client's UI it does "outStream.println()"
twice to send an identifier and a request ID to the server.

The server starts up creating these connections:

inStream = new BufferedReader(new
InputStreamReader(client.getInputStream()));
outStream = client.getOutputStream();
printStream = new PrintWriter(outStream, true);
objOutStream = new ObjectOutputStream(outStream);

When the request for the object is recieved it does this to send the
object to the client:

if (objOutStream != null)
{
try
{
objOutStream.writeObject(testObject);
objOutStream.flush();
}
catch (IOException ioe)
{
System.out.println("IOException Error: " +
ioe.getMessage());
}
}

The client recieves the object with this code. This is also where the
exception is being caught:

try
{
TestObject tObj = (TestObject) objectInStream.readObject();
if (tObj != null)
{
responseTextArea.setText(tObj.toString());
}
else
{
System.out.println("Error: Null tObj");
}
}
catch (EOFException eofe)
{
System.out.println("EOF Exception: " + eofe.getMessage());
}
catch (IOException ioe)
{
// This is the message I always see
System.out.println("IO Exception: " + ioe.getMessage());
}
catch (ClassNotFoundException cnfe)
{
System.out.println("Class not found: " + cnfe.getMessage());
}

Any ideas what I'm doing wrong? Or do you need more info?

Back to top
hiwa
Guest





PostPosted: Wed Jul 20, 2005 11:28 pm    Post subject: Re: Socket failure following writeObject Reply with quote



"maestroff" <maestroff (AT) hotmail (DOT) com> wrote

Quote:
I have a test program I've been working on to experiment with socket
communication. Well actualy 2 programs - 1 client & 1 server program.
Currently the client can request 2 things to be sent from the server
and displayed by the client. First is a simple java.util.Date object
that contains the server's current date-time. That works fine. But then
I tried to request a complex object I wrote. It contains several
private variables, a public enumeration variable, and an inner class
with its own private variables. Both the outer and inner classes
implement Serializable.

The problem is that while I can get and use the object fine the first
time the client sends the request, on any subsequent try I get an
IOException with a message of null. This is true even if a request for
the object is followed by the simpler Datetime request. As soon as the
one object request is done, all further communication causes
IOExceptions.

When the client program is started it creates these connections:

try
{
socket = new Socket(HOST_NAME, SOCK_PORT);
outStream = new PrintWriter(socket.getOutputStream(), true);
inStream = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
objectInStream = new
ObjectInputStream(socket.getInputStream());
}

When I click a button on the client's UI it does "outStream.println()"
twice to send an identifier and a request ID to the server.

The server starts up creating these connections:

inStream = new BufferedReader(new
InputStreamReader(client.getInputStream()));
outStream = client.getOutputStream();
printStream = new PrintWriter(outStream, true);
objOutStream = new ObjectOutputStream(outStream);

When the request for the object is recieved it does this to send the
object to the client:

if (objOutStream != null)
{
try
{
objOutStream.writeObject(testObject);
objOutStream.flush();
}
catch (IOException ioe)
{
System.out.println("IOException Error: " +
ioe.getMessage());
}
}

The client recieves the object with this code. This is also where the
exception is being caught:

try
{
TestObject tObj = (TestObject) objectInStream.readObject();
if (tObj != null)
{
responseTextArea.setText(tObj.toString());
}
else
{
System.out.println("Error: Null tObj");
}
}
catch (EOFException eofe)
{
System.out.println("EOF Exception: " + eofe.getMessage());
}
catch (IOException ioe)
{
// This is the message I always see
System.out.println("IO Exception: " + ioe.getMessage());
}
catch (ClassNotFoundException cnfe)
{
System.out.println("Class not found: " + cnfe.getMessage());
}

Any ideas what I'm doing wrong? Or do you need more info?
In your current description, protocol part or handshake part btw s and c

is vague.

Back to top
Nigel Wade
Guest





PostPosted: Thu Jul 21, 2005 9:49 am    Post subject: Re: Socket failure following writeObject Reply with quote



maestroff wrote:

Quote:
I have a test program I've been working on to experiment with socket
communication. Well actualy 2 programs - 1 client & 1 server program.
Currently the client can request 2 things to be sent from the server
and displayed by the client. First is a simple java.util.Date object
that contains the server's current date-time. That works fine. But then
I tried to request a complex object I wrote. It contains several
private variables, a public enumeration variable, and an inner class
with its own private variables. Both the outer and inner classes
implement Serializable.

The problem is that while I can get and use the object fine the first
time the client sends the request, on any subsequent try I get an
IOException with a message of null. This is true even if a request for
the object is followed by the simpler Datetime request. As soon as the
one object request is done, all further communication causes
IOExceptions.

[snip]

Any ideas what I'm doing wrong? Or do you need more info?

What's the actual exception? Is it a StreamCorruptedException? If so, are
you by any chance sending a java.util.Calendar as part of your object?


--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : [email]nmw (AT) ion (DOT) le.ac.uk[/email]
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555

Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.