Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serialization problem: IOException in writeObject()

 
John Cebedo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please provide the stack trace and any and all code snippets involving the ObjectOuputStream (initialization and usage).
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the stack trace:



Here is my Frame class:

 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since it is now a socket problem, here are the lines of code involving ObjectOutputStream:







And here is the SendFrame class:

 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this the only writing code? Could you also show us the reading code?
 
John Cebedo
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic