--- /dev/null
+package org.wamblee.upnpmonitor;
+
+import java.util.logging.Logger;
+
+import org.teleal.cling.UpnpService;
+import org.teleal.cling.UpnpServiceImpl;
+import org.teleal.cling.controlpoint.ControlPoint;
+import org.teleal.cling.model.message.header.DeviceTypeHeader;
+import org.teleal.cling.model.meta.Device;
+import org.teleal.cling.model.types.DeviceType;
+import org.teleal.cling.registry.DefaultRegistryListener;
+import org.teleal.cling.registry.Registry;
+import org.teleal.cling.registry.RegistryListener;
+
+public class Main {
+
+ private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
+
+ public static class UpnpStack {
+ private UpnpService upnpService;
+ private ControlPoint controlPoint;
+ private DeviceType deviceType;
+
+ public UpnpStack() {
+ RegistryListener listener = new DefaultRegistryListener() {
+ @Override
+ public void deviceAdded(Registry aRegistry, Device aDevice) {
+ super.deviceAdded(aRegistry, aDevice);
+ System.out.println("Device added: " +
+ aDevice.getDisplayString());
+ System.out.println(aDevice.getType());
+ }
+
+ @Override
+ public void deviceRemoved(Registry aRegistry, Device aDevice) {
+ super.deviceRemoved(aRegistry, aDevice);
+ System.out.println("Device removed: " +
+ aDevice.getDisplayString());
+ }
+ };
+ upnpService = new UpnpServiceImpl(listener);
+ controlPoint = upnpService.getControlPoint();
+ deviceType = new DeviceType("schemas-upnp-org", "MediaServer");
+
+ }
+
+ public void search() {
+ controlPoint.search(new DeviceTypeHeader(deviceType));
+ }
+
+ public void shutdown() {
+ upnpService.shutdown();
+ }
+ }
+
+ public static void main(String[] aArgs) throws Exception {
+
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ System.out.println("Shutdown hook");
+ }
+ });
+
+ for (;;) {
+ UpnpStack stack = new UpnpStack();
+ stack.search();
+ Thread.sleep(10000);
+ stack.shutdown();
+
+ }
+
+ }
+}