| Author |
Serialization problem: IOException in writeObject()
|
John Cebedo
Greenhorn
Joined: Sep 23, 2006
Posts: 11
|
|
Hi, I am in the middle of a networking project. The project is a pair of programs: a Server and a Client. The Client will ask the Server for some file and the Server will try to send the requested file to the Client. My problem is that I keep getting an IOException when trying to use the ObjectOutputStream's writeObject() method. This happens when I am trying to send packets to the Client. In my project, a packet is represented by an instance of a class I made called Frame which implements Serializable. This simple block of code generates the error: Any hints on what I am doing wrong?
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1407
|
|
|
Could you please provide the stack trace and any and all code snippets involving the ObjectOuputStream (initialization and usage).
|
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Can you also tell us some more about class Frame: 1) what are its non-static non-transient fields? 2) what is its super class? 3) is that class also Serializable? 4a) if so, goto step 1 for the super class 4b) if not, does that class have a constructor without parameters? For a class to be serializable, all non-static non-transient fields have to be primitives or Serializable themselves. Any object being stored in such a field, like in arrays, Collections or models, have to be primitive or Serializable too. The same holds for the super class, unless there is a constructor without parameters.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1407
|
|
Shoudn't all those oversights result in either an InvalidClassException or a NotSerializableException though? [ April 08, 2008: Message edited by: Jelle Klap ]
|
 |
John Cebedo
Greenhorn
Joined: Sep 23, 2006
Posts: 11
|
|
Here is the stack trace: Here is my Frame class:
|
 |
Jelle Klap
Bartender
Joined: Mar 10, 2008
Posts: 1407
|
|
Looks like a call to the Socket's InputStream.read() method is being attempted after the connection has been broken by the remote party. Not so much a serialization problem as far as I can tell. In any case the Frame class is perfectly serializable.
|
 |
John Cebedo
Greenhorn
Joined: Sep 23, 2006
Posts: 11
|
|
Oops, I didn't copy the stack trace correctly. It should look like this: After adding the line inside the catch block, I get this additional stack trace:
|
 |
John Cebedo
Greenhorn
Joined: Sep 23, 2006
Posts: 11
|
|
Since it is now a socket problem, here are the lines of code involving ObjectOutputStream: And here is the SendFrame class:
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Is this the only writing code? Could you also show us the reading code?
|
 |
John Cebedo
Greenhorn
Joined: Sep 23, 2006
Posts: 11
|
|
Code involving the BufferedReader: My entire algorithm attempting to simulate the Stop-and-Wait scheme: EDIT: added comments in the code explaining how I'm sending the frames [ April 08, 2008: Message edited by: John Cebedo ]
|
 |
 |
|
|
subject: Serialization problem: IOException in writeObject()
|
|
|