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?
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);