Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to use Java to detect LAN cable unplug?

Posted on 2009-03-31
7
736 Views
Last Modified: 2012-05-06
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
0
Comment
Question by:stelectronic
7 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 24029550
>> but it is quite a expensive way to perform checks in a infinite timer to check every 10 mins.

You won't find anything much 'cheaper'. Even if you could find something lower level, it would only be doing something similar so it could generate events
0
 
LVL 3

Expert Comment

by:techmaza
ID: 24029556
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.
0
 

Author Comment

by:stelectronic
ID: 24029710
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.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Expert Comment

by:defi0
ID: 24030723
You could do it within a DLL that you would call using JNI. But it's not straightforward to build.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24030862
>>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?
0
 
LVL 92

Expert Comment

by:objects
ID: 24034482
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

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
type mismatch (Object[] to double[] 4 33
hibernate example using maven 12 56
runtime exception 2 41
ejb message driven bean mdb creation steps 2 15
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question