简体   繁体   中英

Timeout Connection not working properly - Java

I have a code that connects to a balance, using java socket. The problem is that the connection timeout parameter isn't working properly. No matter what parameter is passed, my waiting time is always 24 seconds.

Is there some sort of parameter on the server I should change?

Here's the part of the code that might interest you.

    int TimeOutConnectionMs = TimeOutConnection.intValue() * 1000;

    socket = new Socket();

    socket.connect(new InetSocketAddress(host, portNumber.intValue()) , TimeOutConnection.intValue() * 1000);

The exceptions used are the following

  } catch (SocketTimeoutException e) {
    msgException = e.getMessage();
    logMessage(process, "EXCEPTION", niveauLog.intValue(), "SocketTimeoutException: " + msgException, host + "_" + portNumber);

  } catch (java.net.SocketException e) {
    msgException = e.getMessage();
    logMessage(process, "EXCEPTION", niveauLog.intValue(), "java net Socket Exception: " + msgException, host + "_" + portNumber);

  } catch (java.net.UnknownHostException e) {
    msgException = e.getMessage();
    logMessage(process, "EXCEPTION", niveauLog.intValue(), "java net Unknown Host Exception: " + msgException, host + "_" + portNumber);

Thanks for your help

您乘以1000两次,因此您的实际连接超时是您认为的1000倍。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM