user3782779
user3782779

Reputation: 1689

Socket client how setSoTimeout

I need to set time for max connection time in a socket client. But if I do like the following code, does not work, because line one open a connection and is a blocking function and never run line two.

How can I setSoTimeout before open connection?

Socket s = new Socket(server.host, server.port);                
s.setSoTimeout(server.time);

Upvotes: 1

Views: 582

Answers (1)

Alboz
Alboz

Reputation: 1851

Socket socket=new Socket();   
socket.connect(new InetSocketAddress(host,port),timeout); 

Upvotes: 1

Related Questions