0

Its a simple problem... I placed the socket code under a button, if server is present it respond very quickly if not it takes time to respond.... I want to shorter that time , is there any way?

2
Contributors
1
Reply
7
Views
5 Years
Discussion Span
Last Post by ~s.o.s~
2

Look into the "connect()" method of the `Socket` class. Basically, you create a blank socket and ask it to connect to a given destination with a specific timeout. This connect() call blocks until a connection was made or timeout was encountered.

// untested
final Socket sock = new Socket();
final int timeOut = (int)TimeUnit.SECONDS.toMillis(5); // 5 sec wait period
sock.connect(new InetSocketAddress("host", 8080), timeOut);
Votes + Comments
.............................................................................................
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.