Skip to main content

java.net.SocketException: Connection reset

1 reply [Last post]
ackumar
Offline
Joined: 2005-01-24
Points: 0

Hai,

When I tried to read a HTML page using URLConnection I got the following Exception.
I need help in solving this problem.

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:220)
at java.io.BufferedInputStream.read(BufferedInputStream.java:277)
at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:221)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:662)
at java.io.FilterInputStream.read(FilterInputStream.java:111)
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:408)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:450)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:182)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)

The code recursively reads the online pages and writes into a file. This readPage method is recursively. This code work fine, but for some pages it gives the exception (given in previous post) and jumps to next page.

Here is my sample code:

readPage(Sring url,String tempfile)
{
try{
String line="";
byte[] buf;
FileOutputStream fo = new FileOutputStream(tempfile);
URLConnection con = new URL(url).openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
while(((line = br.readLine()) != null)) {
line = line + '\n';
buf = line.getBytes();
fo.write(buf);
line = "";
}
br.close();
}catch(Exception ee){ee.printStackTrace();}
}

Regards
ackumar

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sandoz
Offline
Joined: 2003-06-20
Points: 0

Hi ackumar,

I think you posted to the wrong forum.

Paul.