Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

EOFException

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
mzimmer74
Asked:
mzimmer74
  • 3
  • 2
1 Solution
 
mzimmer74Author Commented:
there should of course be a ";" after "return buffer" in my receive method.
0
 
Venci75Commented:
this means that you call your receive() method when the socket connection is closed and there is no data to read
0
 
mzimmer74Author Commented:
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
 
Venci75Commented:
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
 
mzimmer74Author Commented:
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

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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