D-Dᴙum
D-Dᴙum

Reputation: 7890

Capture Network Connectivity Event

Is it possible to capture network events using Java?

For example, when I connect my ethenet adapter to a hub there is 'connectivity' and this is detected by windows XP and a 'bubble' displayed to the user. Does Windows also broadcast an event which can be captured by applications and more specifically applications written in Java?

Upvotes: 2

Views: 769

Answers (2)

Gray
Gray

Reputation: 116858

As far as I know there is not an event for this that Java can detect -- it's very OS specific. What you can do is poll the available network interfaces every so often.

Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();

Upvotes: 1

Mike Thomsen
Mike Thomsen

Reputation: 37506

The best you could do is detect whether or not you have network connectivity by creating a thread which periodically polls a URL that you can trust will be up. Detecting network events in windows would require a JNI call to Windows APIs.

Upvotes: 1

Related Questions