Solved

How to use Java to detect LAN cable unplug?

Posted on 2009-03-31
7
727 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Loop 6 59
check java version using powershell 13 82
eclipse buid path vs tomcat lib path 10 22
Java string replace 11 43
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

786 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