Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何用java编写这个问题,或者如何连接一个客户机和4个服务器_Java_Netbeans - Fatal编程技术网

如何用java编写这个问题,或者如何连接一个客户机和4个服务器

如何用java编写这个问题,或者如何连接一个客户机和4个服务器,java,netbeans,Java,Netbeans,您要构建一个包含一个客户端和4个服务器的系统 客户端尝试连接到服务器1;它失败了 The failure is due to the fact that the server starts after the client 然后尝试连接到服务器2;它失败了 The failure is due to the fact that server 2 is busy, and responds to the client request late. The failure is due to i

您要构建一个包含一个客户端和4个服务器的系统

客户端尝试连接到服务器1;它失败了

 The failure is due to the fact that the server starts after the client
然后尝试连接到服务器2;它失败了

The failure is due to the fact that server 2 is busy, and responds to the client request late.
The failure is due to incorrect port number used by the client
然后尝试连接到服务器3;它失败了

The failure is due to the fact that server 2 is busy, and responds to the client request late.
The failure is due to incorrect port number used by the client
然后客户端成功地连接到客户端

客户端打印其4次尝试的结果:

无法连接到服务器1

无法连接到服务器2

无法连接到服务器3


成功连接到服务器4

,这种逻辑通常更好地在应用程序之外进行处理,但是如果您想在应用程序上实现它,则应该考虑使用诸如:

的库。
  • 使用resilience4j,您可以在重试中定义尝试次数,然后在每次尝试时更改url

        val retry = Retry.of("retrying", RetryConfig.custom<RetryConfig>()
            .maxAttempts(3)
            .intervalFunction { attempt: Int -> (attempt * 2).toLong() }
            .build())
    
        val responses = ArrayDeque<Response>()
        responses.add(Response(Status.INTERNAL_SERVER_ERROR))
        responses.add(Response(Status.OK))
    
        val retrying = ResilienceFilters.RetryFailures(retry,
            isError = { r: Response -> !r.status.successful }
        ).then {
            val response = responses.removeFirst()
            println("trying request, will return " + response.status)
            response
        }
    
    val retry=retry.of(“retrying”,RetryConfig.custom())
    .maxports(3)
    .intervalFunction{trunt:Int->(trunt*2).toLong()}
    .build())
    val responses=ArrayDeque()
    添加(响应(状态.内部服务器错误))
    添加(响应(状态为OK))
    val retrying=ResilienceFilters.RetryFailures(重试,
    isError={r:Response->!r.status.successful}
    ).那么{
    val response=responses.removeFirst()
    println(“正在尝试请求,将返回”+response.status)
    响应
    }
    
    我们不能为你写家庭作业。如果你不知道如何开始,问你的老师或其他人。如果您有特定的问题,请编辑您的问题,使其与此相关。