javatry-catchioexceptionsocketexception

SocketException inside IOException


I'm getting java.net.SocketException in the portion of code with try-catch IOException with no output of errors. SocketException is a successor of IOException so why?

try {
        Socket net = new Socket(TARGET, PORT);
        sendRawLine("GET / HTTP/1.1", net);
        sendRawLine("request", net);
        net.close();
    } catch (IOException e) {
        // System.out.println(e);
    }

java.net.SocketException: Connection reset
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:118)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    at java.io.BufferedWriter.flush(BufferedWriter.java:254)
    at com.Joorvish.sendRawLine(Joorvish.java:125)
    at com.Joorvish.createSockets(Joorvish.java:99)
    at com.Lorento.run(Lorento.java:15)
    at java.lang.Thread.run(Thread.java:744)
java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
    at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
    at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
    at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    at java.io.BufferedWriter.flush(BufferedWriter.java:254)
    at com.Joorvish.sendRawLine(Joorvish.java:125)
    at com.Joorvish.createSockets(Joorvish.java:100)
    at com.Lorento.run(Lorento.java:15)
    at java.lang.Thread.run(Thread.java:744)

Solution

  • java.net.SocketException: Broken pipe

    This means you've written to a connection that has already been closed by the peer. The reason for that is almost certainly the invalid HTML that you appear to be writing.