• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

StreamCorruptedException ?!

I'm able to do the following with no problems at all:


Socket server=..;
..

out=new DataOutputStream(server.getOutputStream());
in =new DataInputStream(server.getInputStream());
oos=new ObjectOutputStream(server.getOutputStream());


But when I try the following:


ois=new ObjectInputStream(server.getInputStream());


I get the following exception:

java.io.StreamCorruptedException: invalid stream header: 00095253
      at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
           .
           .

(on the ObjectInputStream line..)


Help? :(

Thanks
0
InteractiveMind
Asked:
InteractiveMind
  • 6
  • 4
  • 2
4 Solutions
 
InteractiveMindAuthor Commented:
(The server-side is able to open all four streams no problem..)
0
 
objectsCommented:
you cannot open a ObjectInputStream and DataInputStream on the same stream like that, ?(and it doesn't make a lot of sense to do it).
You can try opening the OIS first, but I'd suggest not opening a DataInputStream.
0
 
CEHJCommented:
Was the stream *written* with ObjectOutputStream?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
InteractiveMindAuthor Commented:
Sorry for the delay guys;

I now see that using a DataInputStream and an OutputInputStream is rather illogical; so I've cut it down to just an ObjectInputStream. This has stopped the exception.

However, now, although I'm able to open an ObjectOutputStream with no problem
oos=new ObjectOutputStream(server.getOutputStream());
my code just hangs when I attempt to open an ObjectInputStream
ois=new ObjectInputStream(server.getInputStream());

(I open the ois straight after the oos)

I'm stumped.
0
 
CEHJCommented:
Is that happening *before* you try to read from that input stream?
0
 
InteractiveMindAuthor Commented:
yes
0
 
CEHJCommented:
Is it definitely this line that causes it to hang?

>>ois=new ObjectInputStream(server.getInputStream());
0
 
InteractiveMindAuthor Commented:
I'm pretty sure it is, yea.

I'm doing the following to make sure:

oos=new ObjectOutputStream(server.getOutputStream());
System.out.println("o");
ois=new ObjectInputStream(server.getInputStream());
System.out.println("i");

It outputs o, but no i (and there's no exception or anything..)  :-\
0
 
InteractiveMindAuthor Commented:
well, i'm in the process of recoding my program.
hopefully that will solve the problem (as i'll be more cautious..); i'll get back to ya'll soon.
0
 
objectsCommented:
> my code just hangs when I attempt to open an ObjectInputStream

change the order you open things at the other end
0
 
InteractiveMindAuthor Commented:
I tried that as well :(


As it goes though, I finished recoding the program just a few mins ago--and am not getting any problems with it :-)
So I'll just put this hanging problem down to bad coding :-P  (it's a large code-and-fix app)

So, I will split the points (although most will be to objects for his solution to my initial issue).


Thanks very much both
0
 
CEHJCommented:
:-)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now