Solved

Java.net.socketException

Posted on 2001-08-02
25
289 Views
Last Modified: 2007-12-19
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
Comment
Question by:jerntat
[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
  • 9
  • 7
  • 3
  • +3
25 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6344038
The connection probably times out.
0
 

Author Comment

by:jerntat
ID: 6344062
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
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6344162
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6344167
0
 
LVL 2

Expert Comment

by:sateesh_babu
ID: 6344179
0
 

Author Comment

by:jerntat
ID: 6344194
no text?
0
 

Author Comment

by:jerntat
ID: 6344200
by the way i am using the URL and URLConnection class where i think this exception came out.

0
 
LVL 33

Expert Comment

by:hongjun
ID: 6344204
0
 

Author Comment

by:jerntat
ID: 6344211
so can you guys see my question?
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6344252
Yes I can read your above comment and your question.

hongjun
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6344895
Post your servlet code, please. It'll make it a lot easier to try and fingure this out.

--Steve
0
 
LVL 92

Expert Comment

by:objects
ID: 6346573
Probably NOT a timeout then.
Next guess is that the servlet is crashing.
0
 

Author Comment

by:jerntat
ID: 6346964
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
 
LVL 92

Expert Comment

by:objects
ID: 6346982
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
 

Author Comment

by:jerntat
ID: 6347000
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
 
LVL 92

Expert Comment

by:objects
ID: 6347052
Shouldn't cause a problem, and if it did u would expect it to always fail.
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6371322
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
 

Author Comment

by:jerntat
ID: 6371554
I have already posted part of my servlet code up. I have trace the exception and that it occur during the connection() method.
0
 
LVL 92

Accepted Solution

by:
objects earned 60 total points
ID: 6371597
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
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6371599
No, this code is just your client's code. But we need the code on the server side...
0
 

Author Comment

by:jerntat
ID: 6382534
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
 
LVL 92

Expert Comment

by:objects
ID: 6382551
SOunds like it's a (intermittent) problem with the sites your connecting to. See my comment above regards retrys.
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6383173
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
 

Author Comment

by:jerntat
ID: 6383308
Thanks again guys, I think retrying the connection will work.
0
 
LVL 92

Expert Comment

by:objects
ID: 6383322
Thanks for the points :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 …
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:
Suggested Courses

734 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