Simple code, complex problem: "Software caused connection abort: recv failed"

Discussion in 'Java' started by taras.di@gmail.com, Aug 22, 2005.

  1. Guest

    Hi everyone.

    I'm trying to write code that takes input from a text file, writes it
    to a socket connected to a webserver (that I have written as part of a
    university assignment), then reads the output of the webserver - sounds
    simple enough (especially with the abstraction provided by java).
    However, when I run the code, a SocketException is thrown. I'm quite
    sure that the webserver isn't a fault - its output guarantees that the
    correct response is being sent. Also, connecting to the webserver
    using a broswer or telnet shows no problems. The code for the test
    bench is shown below:

    Socket socket = new Socket("127.0.0.1", 9836);
    DataOutputStream outToClient = new DataOutputStream
    (socket.getOutputStream());
    BufferedReader inFromClient = new BufferedReader
    (new InputStreamReader(socket.getInputStream()));
    outToClient.writeBytes("GET index.html\r\n");
    String toPrint = inFromClient.readLine(); // this causes
    the EXCEPTION to be thrown
    System.out.println(toPrint);

    Looks easy enough. When I step through the code using JBuilder's
    debugger, all is well. Sometimes, no Exception is thrown when the code
    is run through at full pace, but most of the time the exception is
    thrown. The output is shown below:

    java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    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)
    at TestBench.main(TestBench.java:31)

    I've browsed the web for a couple of hours looking for answers, but
    they all seem to be regarding SQL/Apache/Tomcat (not simple java code).
    Any gurus have an idea of what might be happening?

    Thanks

    Taras
    , Aug 22, 2005
    #1
    1. Advertising

  2. shakah Guest

    wrote:
    > Hi everyone.
    >
    > I'm trying to write code that takes input from a text file, writes it
    > to a socket connected to a webserver (that I have written as part of a
    > university assignment), then reads the output of the webserver - sounds
    > simple enough (especially with the abstraction provided by java).
    > However, when I run the code, a SocketException is thrown. I'm quite
    > sure that the webserver isn't a fault - its output guarantees that the
    > correct response is being sent. Also, connecting to the webserver
    > using a broswer or telnet shows no problems. The code for the test
    > bench is shown below:
    >
    > Socket socket = new Socket("127.0.0.1", 9836);
    > DataOutputStream outToClient = new DataOutputStream
    > (socket.getOutputStream());
    > BufferedReader inFromClient = new BufferedReader
    > (new InputStreamReader(socket.getInputStream()));
    > outToClient.writeBytes("GET index.html\r\n");
    > String toPrint = inFromClient.readLine(); // this causes
    > the EXCEPTION to be thrown
    > System.out.println(toPrint);
    >
    > Looks easy enough. When I step through the code using JBuilder's
    > debugger, all is well. Sometimes, no Exception is thrown when the code
    > is run through at full pace, but most of the time the exception is
    > thrown. The output is shown below:
    >
    > java.net.SocketException: Software caused connection abort: recv failed
    > at java.net.SocketInputStream.socketRead0(Native Method)
    > at java.net.SocketInputStream.read(SocketInputStream.java:129)
    > 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)
    > at TestBench.main(TestBench.java:31)
    >
    > I've browsed the web for a couple of hours looking for answers, but
    > they all seem to be regarding SQL/Apache/Tomcat (not simple java code).
    > Any gurus have an idea of what might be happening?
    >
    > Thanks
    >
    > Taras


    I'm not that familiar with the rules for "simple" HTTP requests (v
    0.9?), but are you missing the terminating empty line in the request
    header? Do you see the same behavior if you issue HTTP/1.0 requests and
    terminate the request header properly with an empty new line, i.e.:

    outToClient.writeBytes("GET index.html HTTP/1.0\r\n\r\n") ;
    shakah, Aug 22, 2005
    #2
    1. Advertising

  3. Re: Simple code, complex problem: "Software caused connection abort:recv failed"

    shakah wrote:
    > wrote:
    >
    >> outToClient.writeBytes("GET index.html\r\n");


    > I'm not that familiar with the rules for "simple" HTTP requests (v
    > 0.9?), but are you missing the terminating empty line in the request
    > header? Do you see the same behavior if you issue HTTP/1.0 requests and
    > terminate the request header properly with an empty new line, i.e.:
    >
    > outToClient.writeBytes("GET index.html HTTP/1.0\r\n\r\n") ;


    The rules for HTTP 0.9 is that no-one has supported it for years. You
    probably want to suppply a Host: line too. Virtual web servers are a tad
    common these days.

    Shouldn't it be /index.html? Relative URLs don't make a great deal of
    sense in this context.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Aug 22, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.amnet.net.au
    Replies:
    1
    Views:
    574
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. jaco
    Replies:
    0
    Views:
    1,713
  3. sushali
    Replies:
    0
    Views:
    6,608
    sushali
    Sep 1, 2005
  4. Replies:
    1
    Views:
    4,388
  5. Stanimir Stamenkov
    Replies:
    2
    Views:
    744
    Stanimir Stamenkov
    Oct 25, 2005
Loading...

Share This Page