SocketException处理

我不能理解简单的事情。 我有一个处理socket输入的类。 我有一个catch语句:

    public class EntryPoint implements Runnable {

        private Socket socket = null;
        private BufferedReader br = null; // receives data from the destination

...

        public void run() {     
            String command = null;      // buffer for holding one request from command line
            StringReader commandReader = null; // stream for reading command
            try {
                while (!socket.isClosed() && (command = br.readLine()) != null) {               
                    try {
                        command = command.trim();
                        commandReader = new StringReader(command);
                        Request req = JAXB.unmarshal(commandReader, Request.class); 
                        commandReader.close();  
                        dispatcher.sendRequest(req);                                        
                    } catch(DataBindingException ex) {
                        response.sendResponse(SystemMessageFactory.INVALID);
                        response.sendResponse(SystemMessageFactory.SOCKET_SHUTDOWN);
                    }                       
                }
            } catch (SocketException e) {
                System.out.println("Socket Exception");
            } catch (IOException e) {
                Logger.getLogger("server").log(Level.SEVERE, 
                        "Error reading the command input of the client!", e);
            } 
        }       

    }

当对方突然关闭套接字时,发送连接重置。 堆栈跟踪是:

16.07.2013 1:39:51 EntryPoint run
SEVERE: Error reading the command input of the client!
java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
    at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
    at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
    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 blood.steel.server.EntryPoint.run(EntryPoint.java:36)
    at java.lang.Thread.run(Thread.java:662)

这怎么可能? 我抓住了两次! SocketException被捕获到它自己的catch-clause和IOException catch子句中。 但没有任何反应! 它不捕获套接字异常。 我该如何处理它,以及这种行为的起因是什么?


SocketExceptioon不是java.net.的一个java.net. 检查你的进口。

或者你没有运行你认为你是的代码。

链接地址: http://www.djcxy.com/p/56569.html

上一篇: SocketException Handling

下一篇: What does "connection reset by peer" mean?