Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URL Timer? Is it Possible?

Status
Not open for further replies.

luthriaajay

Programmer
Jan 29, 2002
41
FR
Is there any variable in the URL method which can be set to a particular
value so that when we make a URL connection,the system tries to connect to the
URL for a specific number of seconds as set in this variable and if it doesnt
connect it returns back??

Can any one help me please? or am I wrong?

Let say you want to connect to a URL within 15 seconds,
if the system does not connect,ot returns 'Connection Timed out.Try Again'

ajay
 
Hai Friend,
We faced same type of implementation too. We didn't get direct function for this purpose. We started one thread to control this URL verifier function and thread have the life time of 15 seconds. If the thread didn't get any reply from URL verifier, then it kills the verifying process and give the statement the URL is not verified and time out error.

I hope this idea may helpfull to u..

With Regards
Siva
::)
 
PLEASE CAN SOME ONE MODIFY MY CODE SO THAT I CAN CONNECT TO THE SERVER WITHIN 15 SECONDS AFTER WHICH I RETURN BACK?

WHERE SHUD THE THREADS BE WRITTEN?

public class HttpHandler
{
private static String sURL="localhost";
static String sMessage="Hello Server..Client sending Data";

public static void main(String[] args)
{
sendData(sMessage);
}

public static void sendData(String sMess)
{
HttpURLConnection hpCon=null;
String response=null;

try {
URL url=null;
String uri = " + sURL + ":8080/servlet/threads.Recieve_Http_Data";
url = new URL(uri);
hpCon = (HttpURLConnection)url.openConnection();

hpCon.setDoOutput(true);
hpCon.setDoInput(true);

// Transfer Data over http
DataOutputStream dos = new DataOutputStream(hpCon.getOutputStream());
dos.writeUTF(sMess);

//Response from the Server
DataInputStream dis = new DataInputStream(hpCon.getInputStream());

try {
response = dis.readUTF();
System.out.println("SERVER RESPONSE : " + response);
}finally
{ dos.close();
dis.close();
}

}catch(IOException e)
{
System.out.println("Error in Client " + e);
}

}

} // End of Class HttpHandler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top