網絡_sockets_ssl_ldaps

sun.security.ssl.SSLSocketFactoryImpl

sun.security.ssl.SSLSocketImpl

遇到問題,想人爲設置socket timeout的時間,timeout的異常是下圖,用的是ldap 的ssl鏈接。

設置com.sun.jndi.ldap.connect.timeout沒有工作,查找到的相關資料不多,也沒找到答案。有說jdk版本低於1.5不支...

有篇:

https://stackoverflow.com/questions/35305461/no-connection-timeout-for-sun-sslsocketimpl-potential-bug

 

debug代碼,能看到,配置ssl了,走到這一步,設置默認timeout=0!

 SSLSocketImpl(SSLContextImpl var1, String var2, int var3) throws IOException, UnknownHostException {
        this.protocolVersion = ProtocolVersion.DEFAULT;
        this.isFirstAppOutputRecord = true;
        this.heldRecordBuffer = null;
        this.preferLocalCipherSuites = false;
        this.host = var2;
        this.serverNames = Utilities.addToSNIServerNameList(this.serverNames, this.host);
        this.init(var1, false);
        InetSocketAddress var4 = var2 != null ? new InetSocketAddress(var2, var3) : new InetSocketAddress(InetAddress.getByName((String)null), var3);
        this.connect(var4, 0);
    }

最後,找到一篇相關文章,

Socket筆記之深入分析java中的ConnectionTimedOut,有了進一步的瞭解;

轉載結論如下:

java中socket

不指定timeout,超時時間是通過操作系統底層tcpip參數決定的,不同操作系統的參數不一樣(比如centos和mac的參數就不同)
指定timeout,此時如果timeout設置的時間小於操作系統內核中設置的時間,則以指定的timeout爲準。如果timeout設置的時間大於操作系統內核中的設置的時間,比如在centos6.7中設置sysctl net.ipv4.tcp_syn_retries=1(3s),此時即使在java的socket參數上設置大於3s的值程序還是會在3s時超時(即在應用層設置時無效的)
————————————————
版權聲明:本文爲CSDN博主「jannals」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/usagoole/article/details/81317966

 

 

相關參考:

servlet 和 socket區別:https://blog.csdn.net/yuqilin520/article/details/82915682

Socket筆記之深入分析java中的ConnectionTimedOut

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章