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

Java.net.socketException

Hello, Anybody know what does this exception means?I get it when my servlet try to fetch a page but usually i can click refresh on my browser to get around the problem. This exception also only occur occasionally but pretty frequent.

java.net.SocketException:unexpected end of file from server
0
jerntat
Asked:
jerntat
  • 9
  • 7
  • 3
  • +3
1 Solution
 
objectsCommented:
The connection probably times out.
0
 
jerntatAuthor Commented:
but the exception came out only less then a second after i run the servlet.

hmm...even then is there anyway i can extend the time for the connection to wait before time out?
0
 
sateesh_babuCommented:
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
sateesh_babuCommented:
0
 
sateesh_babuCommented:
0
 
jerntatAuthor Commented:
no text?
0
 
jerntatAuthor Commented:
by the way i am using the URL and URLConnection class where i think this exception came out.

0
 
jerntatAuthor Commented:
so can you guys see my question?
0
 
hongjunCommented:
Yes I can read your above comment and your question.

hongjun
0
 
sdussingerCommented:
Post your servlet code, please. It'll make it a lot easier to try and fingure this out.

--Steve
0
 
objectsCommented:
Probably NOT a timeout then.
Next guess is that the servlet is crashing.
0
 
jerntatAuthor Commented:
The code look something like :

private void getWebPage()
{
   try{
     connect();
     fetch();
     disconnect();
   }
   catch(Exception ex)
   {
      System.out.println(ex.toString());
   }

}


private void connect()
{
    URLConnection con;
    con = url.openConnection();  //url is a URL object
    con.setUseCaches(false);
    con.setDoInput(true); //tongrong

    //Then I open a data input stream as follow
    InputStream in = url.openStream();
    Reader myreader = new InputStreamReader(in, "latin1");
    this.reader = new BufferedReader(myreader);
}          

fetch() is just reading in the data and put it into a buffer. I think the exception would have occur in the connect() method. But i dont know where.

If the servlet crash why would it still run when i click the refreshed button on my browser?
0
 
objectsCommented:
Put some debug into your servlet logging what its doing and where its up to.  This will help you get an idea what's happening when its failing.
0
 
jerntatAuthor Commented:
is there any chance that this could be cause by running on a different version web servlet? I compile my code using JSDK2.1 but i think the server that I run my servlet in is using JSDK2.0.
0
 
objectsCommented:
Shouldn't cause a problem, and if it did u would expect it to always fail.
0
 
dnoelppCommented:
Just a comment: Your socket exception means that your client got an unexpected end of file or that something unusual happened with the servlet connection. To configure this out we need the servlet source code (as Steve (sdussinger) already asked for).

It could be that your servlet is behaving fine most of the time and sometimes not, so then this is a bug in your servlet. Please check your servlet carefully that it really doesn't quit unexpectedly or manipulates it output in a bad way.
0
 
jerntatAuthor Commented:
I have already posted part of my servlet code up. I have trace the exception and that it occur during the connection() method.
0
 
objectsCommented:
So is the socketException being thrown in your servlet?
In which case it's probably a problem with the site your connecting to and out of your control. If it's just an intermittent thing then maybe have your servlet retry the connections a few times on failure.
0
 
dnoelppCommented:
No, this code is just your client's code. But we need the code on the server side...
0
 
jerntatAuthor Commented:
It usually works when i click refreshed on my browser.

The code is from part of my servlet which is running locally on my harddisk. I test it using Internet explorer to access to it. this servlet is something like a proxy server that relay the user request to the Internet. this exception occur when my servlet tries to connect to a certain website by request from a local user.
0
 
objectsCommented:
SOunds like it's a (intermittent) problem with the sites your connecting to. See my comment above regards retrys.
0
 
dnoelppCommented:
Yes, objects is right. The code you posted just looked like client code, but your servlet is client to another web server... I am sorry having told you "just your's client code".

Then just build in an extra functionality in your proxy servlet: On disconnect retry a few times and then report an error message HTML page to the proxy client. (objects already said this; I repeated the same advice in different words :-)
0
 
jerntatAuthor Commented:
Thanks again guys, I think retrying the connection will work.
0
 
objectsCommented:
Thanks for the points :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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