 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
maestroff Guest
|
Posted: Wed Jul 20, 2005 5:38 pm Post subject: Socket failure following writeObject |
|
|
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
|
Posted: Wed Jul 20, 2005 11:28 pm Post subject: Re: Socket failure following writeObject |
|
|
"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
|
Posted: Thu Jul 21, 2005 9:49 am Post subject: Re: Socket failure following writeObject |
|
|
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 |
|
 |
|
|
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
|
|