0

Can any one help me in setting the connection time out in java. I have this piece of code.

SSLSocket sslSocket = new SSLSocket(host, port, context); sslSocket.startHandshake();

I know that there is a line which we can add before stating hand shake sslSocket.setSoTimeout(timeout) but as far as i heard setSoTimeout is applicable both for both connection and read time out. I just want for connection time out but not for read time out. In detail, i just want time out if hand shake didnt happen in 10sec. Once hand shake happened, no time out must happen until i get response

Can any one please help me

  • Please see this answer https://stackoverflow.com/a/4969788/836507 – Oleg May 22 '17 at 14:26
  • Using default constructor socket(), can we set the Context parameter ? context parameter is basically for X509 certificate. – thotatinku May 22 '17 at 14:31
  • You can specify connection timeout in connect() call – Oleg May 22 '17 at 14:34
  • connect () method just accepts parms InetAddress and timeout. I am not having option to set the SSLClient Context in connect() method. – thotatinku May 22 '17 at 14:36
  • First you create SSLSocket with the constructor where you pass the context. Then you call its connect() method with the desired timeout – Oleg May 22 '17 at 15:44
  • Socket socket = new Socket(); SSLSocket sslSocket = new SSLSocket(socket, aSslClientContext); sslSocket.connect(new InetSocketAddress(host,port),10000); sslSocket.startHandshake(); Does this work? – thotatinku May 23 '17 at 05:13

0 Answers0