java.net.SocketException: Connection reset by peer
at java.net.SocketInputStream.read(SocketInputStream.java:84)
at
sun.servlet.http.HttpInputStream.fill(HttpInputStream.java:346)
at
sun.servlet.http.HttpInputStream.readLine(HttpInputStream.java:239)
at
sun.servlet.http.HttpRequestLine.readLine(HttpRequestLine.java:175)
at
sun.servlet.http.HttpRequestLine.parse(HttpRequestLine.java:148)
at sun.servlet.http.HttpRequest.next(HttpRequest.java:323)
at
sun.servlet.http.HttpServerHandler.handleConnection(HttpServerHandler.java:105)
at
sun.servlet.http.HttpServerHandler.run(HttpServerHandler.java:90)
at java.lang.Thread.run(Thread.java:466)
A solution I have found is to cast the URLConnection returned by
url.openConnection (in the code below) to an HttpURLConnection and
before
terminating, call con.disconnect(). The disconnect() method resides in
the
HttpURLConnection class. However, I don't view this as an
acceptable solution since I am not guaranteed that url.openConnection()
will always give me an HttpURLConnection.
import java.net.*;
import java.io.*;
public class ConnectionTest {
public static void main(String[] args) {
try {
URL url=new URL("http://localhost:8080");
URLConnection con=url.openConnection();
con.setDoOutput(true);
DataOutputStream dataOut=new DataOutputStream(con.getOutputStream());
} catch (Exception e){
System.out.println(e);
}
}
}
You can test this by invoking servletrunner and then compiling and
executing the sample program above. Any ideas?
Cliff Helsel
che...@spacelab.net
snip snip
It seems to me that this is not an error but normal behavior.
Why would you expect anything different if the socket is still
open when your program terminates?
WBB
Cliff Helsel
I think that all you have to do is close the Input and Output Streams
to destroy the connection gracefully.
WBB