This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Re checking the connection  RSS feed

 
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)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!