T
taras.di
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 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