[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

EOFException

Posted on 2002-05-30
5
Medium Priority
?
228 Views
Last Modified: 2010-03-31
Hey all,
I'm seeing a slightly weird error in a client/server program I'm working on.  I have a class I wrote with a send and receive method in it.  These appear to work quite well except for every once in a while I get an EOFException on my readInt() call to inputStream (which is a DataInputStream created from a socket).  I have no idea how to reproduce this regularly, and can't figure out what might be wrong with this.  Please take a look at my send and receive methods to see if I'm missing something.  Thanks.


public void send(byte[] buffer) throws SocketException, IOException
{
   int size = buffer.length;
   outputStream.writeInt(size);
   outputStream.write(buffer);
}

public byte[] receive() throws SocketException, IOException
{
  int size = inputStream.readInt();
  byte[] buffer = new byte[size];
  inputStream.readFully(buffer);
  return buffer
}

0
Comment
Question by:mzimmer74
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 2

Author Comment

by:mzimmer74
ID: 7044334
there should of course be a ";" after "return buffer" in my receive method.
0
 
LVL 9

Accepted Solution

by:
Venci75 earned 200 total points
ID: 7044391
this means that you call your receive() method when the socket connection is closed and there is no data to read
0
 
LVL 2

Author Comment

by:mzimmer74
ID: 7044429
Well, the few times we've seen this exception it's been in the course of "normal" operation.  To the best of my knowledge my socket is alive and the connection should be good.  Now, I suppose I may not know that the socket is closed (ie was shut down by something outside of my control) but is there anything else that might cause this?
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7044471
the only reason to get this could be reading -1 from the Socket stream. -1 means that the connection is closed by the remote host
0
 
LVL 2

Author Comment

by:mzimmer74
ID: 7044566
You got me on the right track with this.  What was happening was every time a user logged in (even incorrectly) I created a new socket connection instead of keeping an old one.  Then, when the user closed out the good connection and shut down the "bad" connection got all confused and crashed.  Basically I just had way too many connections.  Thanks for the help.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question