• Post Reply Bookmark Topic Watch Topic
  • New Topic

Re checking the connection

 
Veerabhadram Mantha
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!
I want to test if connection to a particular to URL exists or not.
(ie whether connectivity exists at that time or not). I have just used ur.openConnection().Will the following code suffice to say that connection to the server exists.

boolean checkConnection()
{
URL url = null;
URLConnection con=null;
boolean connected;
try{
url = new URL("https:ipaddress ortno");
con = url.openConnection();
}
catch(Exception e)
{
}
if(con.getDate()!=0)
connected = true;
else connected = false;
return connected;
}
One more doubt. Can we the above code for Https also.Please do suggest me in this.If this does not serve the pupose please suggest the alternatives
Thanks in advance...
 
Sushil Sharma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not clear what is the purpose of the code. Do you want to test:

1. whether a connection is active/exists between two hosts; or
2. if remote host is reachable and support HTTP(S)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!