Solved

EOFException

Posted on 2002-05-30
5
208 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
  • 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 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
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 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

10 Experts available now in Live!

Get 1:1 Help Now