Socket BufferedReader IOException仅在Windows而不是Linux中引发?

Socket BufferedReader IOException仅在Windows而不是Linux中引发?,linux,server,client,chat,ioexception,Linux,Server,Client,Chat,Ioexception,该项目是一个聊天程序,带有多线程服务器,可处理多个客户端。下面的代码是客户端连接后开始的线程的服务器端代码。ConnectionHandler接受一个已连接的客户端套接字和“ID” run()中调用的静态“broadcast”方法与问题以及finally子句中的两个函数无关 我在Windows10桌面和运行Ubuntu18.04的XPS笔记本电脑上都做过这个项目 一旦在run()方法中捕获IOException,就会处理客户端断开连接。这与Windows上的设计一样有效,但对于Ubuntu则不然

该项目是一个聊天程序,带有多线程服务器,可处理多个客户端。下面的代码是客户端连接后开始的线程的服务器端代码。ConnectionHandler接受一个已连接的客户端套接字和“ID”

run()中调用的静态“broadcast”方法与问题以及finally子句中的两个函数无关

我在Windows10桌面和运行Ubuntu18.04的XPS笔记本电脑上都做过这个项目

一旦在run()方法中捕获IOException,就会处理客户端断开连接。这与Windows上的设计一样有效,但对于Ubuntu则不然。当退出GUI客户端时,似乎只有异常在Windows上被捕获,而在Ubuntu上没有发生。因此,使服务器无法在Linux上工作,并且可以在Windows上完美工作

一般来说,这不是处理客户端断开连接的一种行之有效的方法吗?或者,为了让它在Linux上工作,我还需要修改其他东西吗?我不知道该怎么办,因为我不确定这是我的代码中的错误还是Linux处理Java与Windows的方式不同

任何帮助或提示都将不胜感激。提前谢谢

class ConnectionHandler implements Runnable
{

//Begin declarations for new client thread
int clientId;
Socket connection;
BufferedReader reader;
BufferedWriter writer;
String message;
//end declarations for new client thread

public ConnectionHandler(int clientId, Socket connection)
{
    this.clientId = clientId;
    this.connection = connection;    
}

@Override
public void run()
{

    try 
    {
        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        writer = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream()));
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }    


    try 
    {
        while (true)
        {
            message = reader.readLine();

            if (message != null)
            {

                System.out.println("Message from " + message);

                CrosstalkServer.broadcast(message);

            }
        }
    }
    catch (IOException e)
    {
        System.out.println("Client has disconnected. Recycling client ID: " + clientId);
    }
    finally 
    { 
        //Close the reader, writer, and socket. 
        terminateClient();

        //Client has disconnected, handle client count and recycle client ID
        CrosstalkServer.recycleClientId(this);

    }

}
编辑:我在Windows10、Windows7和Ubuntu18.04上测试了这个程序。经过一些测试,是客户端造成了问题。我在我的Ubuntu笔记本电脑上运行了服务器,测试了一个Windows7客户端和一个Windows10客户端。Windows 7客户端没有引发IOException,而Windows 10引发了IOException。Ubuntu客户端也不会导致IOException。。确定客户端断开连接的更好方法是什么?通过尝试不断向我的客户机arraylist中的每个客户机写入来启动要监视的线程