相关疑难解决方法(0)

从Java代码检查服务器是否在线

我想检查服务器应用程序是否可用.服务器启动后,我想停止检查,直到服务器更改状态.如何使用我的代码:

 private static final String SERVER_ADDRESS = "192.144.10.10";
    private static final int TCP_SERVER_PORT = 8890;
    private static boolean connected = false;
    static Socket s;

    public static void main(String[] args) {

    Timer timer = new Timer();
    timer.schedule(task, 01, 5001); }  

static TimerTask task = new TimerTask() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            if (connected == false)
            {
            System.out.println(hostAvailabilityCheck());
            }
        }
    };

    public static boolean hostAvailabilityCheck()
    { 

        boolean available = true; 
        try {               
            if (connected == false) …
Run Code Online (Sandbox Code Playgroud)

java sockets

20
推荐指数
3
解决办法
5万
查看次数

setConnectTimeout与setConnectionTimeToLive对比setSocketTimeout()

有谁可以解释这两者之间的区别是什么:

client = HttpClientBuilder.create()
    .setConnectionTimeToLive(1, TimeUnit.MINUTES)
    .build();
Run Code Online (Sandbox Code Playgroud)

RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30 * 1000).build();
client = HttpClientBuilder
    .create()
    .setDefaultRequestConfig(requestConfig)
    .build();
Run Code Online (Sandbox Code Playgroud)

使用起来更好setSocketTimeout吗?

java apache-httpclient-4.x

11
推荐指数
2
解决办法
5254
查看次数

SocketTimeoutException在5秒 - 任何增加的方式?

我正在点击的服务器定期响应5.5秒,但我甚至在5秒内得到SocketTimeoutException.有没有办法增加这个价值?升级到付费等级会让我有这种能力吗?

google-app-engine

6
推荐指数
1
解决办法
1055
查看次数

如何获得可靠的Volley请求,没有重试策略

当我进行慢速连接并发出POST请求时,Volley会多次重试我的请求,之后所有操作都会终止我的命令errorListener.有时,这些重试实际上成功发布了数据.

用户将假设请求失败,但事实上,如果他们刷新数据,他们会看到数据被POST两次到服务器(或者在一堆中有多次成功重试).

我想给Volley一个非常愚蠢的重试政策:

我希望它尝试15秒的请求,如果请求在15秒内没有到达服务器并返回响应以触发errorListener.我不想让它重试.

唯一值得关注的是,如果Volley尝试,请求会在20~25秒内到达服务器,但到那时它会触发errorListener并且数据仍然被POST.

HTTP是否遵循时间限制,之后100%的数据将不会被发布,因为请求花费的时间太长了?也许40秒?如果是这样,那么我可以让请求持续40秒.

在所有:

没有重试并确保100%,如果第一次尝试发布数据,successListener并且如果没有发布(请求因服务器耗时过长或错误响应而死亡)errorListener.

我正在考虑使用defaultRetryPolicy做一些事情... DefaultRetryPolicy(15000, 0, 1)虽然我认为最后一个参数并不重要,因为没有重试的退避点是什么.

我怎样才能实现我要求的两段回复?

android http android-volley

5
推荐指数
0
解决办法
1637
查看次数

查找主机时如何设置套接字的超时时间?

在我的单元测试中,我使用 commons httpclient 请求错误的远程网站,最大超时时间为:

@Test(timeout = 10000)
public void should_not_be_accessible_if_configuration_is_incorrect() throws Exception {
     // use httpclient to visit an invalid remote http web site
}
Run Code Online (Sandbox Code Playgroud)

但是在某些计算机上可能会抛出这样的异常:

java.lang.Exception: test timed out after 10000 milliseconds
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:894)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1286)
at java.net.InetAddress.getAllByName0(InetAddress.java:1239)
at java.net.InetAddress.getAllByName(InetAddress.java:1155)
at java.net.InetAddress.getAllByName(InetAddress.java:1091)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:44)
at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:102)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:357)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:218)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:194)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
Run Code Online (Sandbox Code Playgroud)

似乎它阻塞了方法: java.net.Inet4AddressImpl.lookupAllHostAddr()

我想知道有没有办法为其设置最大超时时间?

java sockets timeout

4
推荐指数
1
解决办法
3560
查看次数