954,545 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sockets

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?

Majestics
Practically a Master Poster
621 posts since Jul 2007
Reputation Points: 199
Solved Threads: 49
 

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);
~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You