相关疑难解决方法(0)

SocketTimeoutException:读取超时

这是一个简单的基于客户端/服务器的ping/pong程序.不幸的是,IT不起作用并显示以下错误消息:

java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
    at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
    at sun.nio.cs.StreamDecoder.read(Unknown Source)
    at java.io.InputStreamReader.read(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

它停在CLIENT TASK 30行,实际上客户端没有读取服务器发送的内容.这里的代码:

服务器

package serverClient;

import java.net.*;
import java.io.*;
import java.util.concurrent.*;

public class Server {

    public static void main(String[]args){


        ExecutorService esp= Executors.newFixedThreadPool(50);
        try(ServerSocket ss= new ServerSocket(1027)){
            while(true){
                try{

                    Socket s=ss.accept();
                    Callable<Void> task=new ServerTask(s);
                    esp.submit(task);

                }
                catch(BindException be){}
                catch(ConnectException ce){}
                catch(NoRouteToHostException nrthe){}
                catch(IOException ioe){ioe.printStackTrace();}
            }
        }
        catch(Exception e){e.printStackTrace();}

    }
}
Run Code Online (Sandbox Code Playgroud)

服务器任务

package serverClient;

import …
Run Code Online (Sandbox Code Playgroud)

java sockets networking socket-timeout-exception

5
推荐指数
1
解决办法
2万
查看次数