Jump to content
View in the app

A better way to browse. Learn more.

Universal Devices Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

java code{Scan Upnp devices in a LAN}

Featured Replies

Posted

Hello,

This is my first post here,

I'm trying to write a simple java code ,

that detects upnp devices and display them.

could you please give me hand to

be able to continue ?!

  • Author

Hello again,

finally i have a java class that helps me displaying upnp devices ,

it displays the services of the device too, but no actions found for the services :cry: ,

System.out.println(services.hasActions()) return false,

it is weird , any ideas ?

package fr.enssat.fgt.upnp.control;

import org.teleal.cling.UpnpService;
import org.teleal.cling.UpnpServiceImpl;
import org.teleal.cling.model.message.header.STAllHeader;
import org.teleal.cling.model.meta.Action;
import org.teleal.cling.model.meta.LocalDevice;
import org.teleal.cling.model.meta.RemoteDevice;
import org.teleal.cling.model.meta.Service;
import org.teleal.cling.registry.Registry;
import org.teleal.cling.registry.RegistryListener;

/**
* Runs a simple UPnP discovery procedure.
* http://4thline.org/projects/cling/core/manual/cling-core-manual.html
*/
public class Test {

   public static void main(String[] args) throws Exception {

       // UPnP discovery is asynchronous, we need a callback
       RegistryListener listener = new RegistryListener() {

           public void remoteDeviceDiscoveryStarted(Registry registry,
                                                    RemoteDevice device) {
               System.out.println(
                       "Discovery started: " + device.getDisplayString()
               );
               Service[] services = device.getServices();

               for(int i=0;i                	System.out.println(services[i].hasActions());
       			}

           }

           public void remoteDeviceDiscoveryFailed(Registry registry,
                                                   RemoteDevice device,
                                                   Exception ex) {
               System.out.println(
                       "Discovery failed: " + device.getDisplayString() + " => " + ex
               );
           }

           public void remoteDeviceAdded(Registry registry, RemoteDevice device) {
               System.out.println(
                       "Remote device available: " + device.getServices().toString()
               );
           }

           public void remoteDeviceUpdated(Registry registry, RemoteDevice device) {
               System.out.println(
                       "Remote device updated: " + device.getDisplayString()
               );
           }

           public void remoteDeviceRemoved(Registry registry, RemoteDevice device) {
               System.out.println(
                       "Remote device removed: " + device.getDisplayString()
               );
           }

           public void localDeviceAdded(Registry registry, LocalDevice device) {
               System.out.println(
                       "Local device added: " + device.getDisplayString()
               );
           }

           public void localDeviceRemoved(Registry registry, LocalDevice device) {
               System.out.println(
                       "Local device removed: " + device.getDisplayString()
               );
           }

           public void beforeShutdown(Registry registry) {
               System.out.println(
                       "Before shutdown, the registry has devices: "
                       + registry.getDevices().size()
               );
           }

           public void afterShutdown() {
               System.out.println("Shutdown of registry complete!");

           }
       };

       // This will create necessary network resources for UPnP right away
       System.out.println("Starting Cling...");
       UpnpService upnpService = new UpnpServiceImpl(listener);

       // Send a search message to all devices and services, they should respond soon
       upnpService.getControlPoint().search(new STAllHeader());


       // Let's wait 10 seconds for them to respond
       System.out.println("Waiting 10 seconds before shutting down...");
       Thread.sleep(10000);

       // Release all resources and advertise BYEBYE to other UPnP devices
       System.out.println("Stopping Cling...");
       upnpService.shutdown();
   }
}

Guest
This topic is now closed to further replies.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.