Solved

Java.net.socketException

Posted on 2001-08-02
25
269 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
  • 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
 
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
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.

 

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

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
create a gui in perl 3 67
rhino JavaScript import, load 25 66
javap bin 2 22
xampp tool 12 21
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

947 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

20 Experts available now in Live!

Get 1:1 Help Now