Solved

Java.net.socketException

Posted on 2001-08-02
25
259 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 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

19 Experts available now in Live!

Get 1:1 Help Now