Posted on 2002-05-30
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;

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

Question by:mzimmer74
  • 3
  • 2

Author Comment

ID: 7044334
there should of course be a ";" after "return buffer" in my receive method.

Accepted Solution

Venci75 earned 50 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

Author Comment

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?

Expert Comment

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

Author Comment

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.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 98
sites similar to codingbat to improve coding hanson skills 3 40
session migration servlets 2 24
javap not working 8 36
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now