我在带有try-catch IOException的代码部分中获得了java.net.SocketException,没有错误输出。 SocketException是IOException的后继者,为什么?

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)

最佳答案

java.net.SocketException:管道损坏


这意味着您已经写入了一个已被对等方关闭的连接。这样做的原因几乎可以肯定是您似乎正在编写的无效HTML。

10-08 13:38