Link to home
Start Free TrialLog in
Avatar of stelectronic
stelectronic

asked on

How to use Java to detect LAN cable unplug?

Hi all

Is there any ways in which I can use Java to detect the event whereby user unplug the LAN cable so that I can do something like turning my icon to another one so as to show it is offline.

I got a way in which a timer where by i check my ipaddress to local host, but it is quite a expensive way to perform checks in a infinite timer to check every 10 mins.

Appreciate if someone has an answer to it
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
U can send ping IP packet thru java.net package every 30 sec time interval and if user on target computer removes the lan cable then connection will be lost and u will catch an exception  which u can use to trigger an ballon tip event message.
Avatar of stelectronic
stelectronic

ASKER

Is there a way in which Java can use Windows event? something like when I unplug a LAN cable, windows will notify me. is there a way for me to capture/hook on that event using listeners?

The reason I dun want to use timers is that it might have out of memory exception if it is allowed to run a long time.
You could do it within a DLL that you would call using JNI. But it's not straightforward to build.
>>The reason I dun want to use timers is that it might have out of memory exception if it is allowed to run a long time.

There's no necessary connection between daemon processes/threads and memory problems.

>>is there a way for me to capture/hook on that event using listeners?

How, do you imagine, would kernel level functionality manage to listen for such events?
There are no events available for this, what you are already doing is the best you can do.
A Timer would be the best for minimizing the memory usage.

http://helpdesk.objects.com.au/java/how-to-execute-code-at-regular-interval