Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.net.InetAddress  RSS feed

 
Rajal Mistry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Friends,
I am trying to write a net work management module , so, in a thread i m calling InetAddress.getByName("200.100.50.15");
wh9ich is on my intranet , so when it is on the n/w the code below shows it is on the network by printing it but as my thread is running and if this system goes out of n/w InetAddress.getByName("200.100.50.15"); should throw a exception and show it is not on network (what i feel), but it is not going into the exception part. Now if i come out of my program and again starts it it is going to exception and showing the message
that system is not on n/w .
Is there anything i m doing worng ..
If anybody can tell a little about the inner implementation of InetAddress, please.
thanx.
code goes here :::
import java.net.*;
public class InetAddressTest
{
public static void main(String args[])
{
SystemsOnNetwork sysonnet=new SystemsOnNetwork();
try
{
sysonnet.th.join();
}catch(Exception ie)
{
}

}
}
class SystemsOnNetwork implements Runnable{

Thread th;
String curr = "200.100.50.15";

SystemsOnNetwork()
{
th = new Thread(this);
th.start();
}

public void run()
{
while (true)
{
try{
InetAddress Inet = InetAddress.getByName(curr); System.out.println(" System is on n/w");
}catch(UnknownHostException uhe){
System.out.println(" System is not on n/w");
}
}
}

}//class
 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bhidu ,
U gotta write a thread for checking the continuety of ip address. FOr that use sleep method .Write this in another mehod or thread and make that thread sleep for some 5 / 10 Mseconds.
Everytime the thread goes up , call the method for checking ip or any processing.
 
Rajal Mistry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sanjay deshpande:
Hi bhidu ,
U gotta write a thread for checking the continuety of ip address. FOr that use sleep method .Write this in another mehod or thread and make that thread sleep for some 5 / 10 Mseconds.
Everytime the thread goes up , call the method for checking ip or any processing.

 
Rajal Mistry
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi bhidu,
Thanks anyway sanjay for trying it out, but it was a catch
reload problem .So, u have to run the program by saying
java -Dsun.net.inetaddr.ttl=1 , so every 1 second catch will be refreshed.
bye.
--raj.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!