Package net.sbbi.upnp

Class Discovery


  • public class Discovery
    extends java.lang.Object
    Class to discover an UPNP device on the network.
    A multicast socket will be created to discover devices, the binding port for this socket is set to 1901, if this is causing a problem you can use the net.sbbi.upnp.Discovery.bindPort system property to specify another port. The discovery methods only accept matching device description and broadcast message response IP to avoid a security flaw with the protocol. If you are not happy with such behaviour you can set the net.sbbi.upnp.ddos.matchip system property to false to avoid this check.
    • Constructor Summary

      Constructors 
      Constructor Description
      Discovery()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static RootDevice[] discover()
      Devices discovering on all network interfaces with default values, all root devices will be searched
      static RootDevice[] discover​(int timeOut, int ttl, int mx, java.lang.String searchTarget)
      Devices discovering on all network interfaces with a given timeout and a given root device to search, as well as a ttl and mx param
      static RootDevice[] discover​(int timeOut, int ttl, int mx, java.lang.String searchTarget, java.net.NetworkInterface ni)
      Devices discovering with a given timeout and a given root device to search on an given network interface, as well as a ttl and mx param
      static RootDevice[] discover​(int timeOut, java.lang.String searchTarget)
      Devices discovering on all network interfaces with a given timeout and a given root device to search
      static RootDevice[] discover​(java.lang.String searchTarget)
      Devices discovering on all network interfaces with a given root device to search
      static void sendSearchMessage​(java.net.InetAddress src, int ttl, int mx, java.lang.String searchTarget)
      Sends an SSDP search message on the network
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Discovery

        public Discovery()
    • Method Detail

      • discover

        public static RootDevice[] discover()
                                     throws java.io.IOException
        Devices discovering on all network interfaces with default values, all root devices will be searched
        Returns:
        an array of UPNP Root device or null if nothing found with the default timeout. Null does NOT means that no UPNP device is available on the network. It only means that for this default timeout no devices responded or that effectively no devices are available at all.
        Throws:
        java.io.IOException - if some IOException occurs during discovering
      • discover

        public static RootDevice[] discover​(java.lang.String searchTarget)
                                     throws java.io.IOException
        Devices discovering on all network interfaces with a given root device to search
        Parameters:
        searchTarget - the device URI to search
        Returns:
        an array of UPNP Root device that matches the search or null if nothing found with the default timeout. Null does NOT means that no UPNP device is available on the network. It only means that for this given timeout no devices responded or that effectively no devices are available at all.
        Throws:
        java.io.IOException - if some IOException occurs during discovering
      • discover

        public static RootDevice[] discover​(int timeOut,
                                            java.lang.String searchTarget)
                                     throws java.io.IOException
        Devices discovering on all network interfaces with a given timeout and a given root device to search
        Parameters:
        timeOut - the time allowed for a device to give a response
        searchTarget - the device URI to search
        Returns:
        an array of UPNP Root device that matches the search or null if nothing found with the given timeout. Null does NOT means that no UPNP device is available on the network. It only means that for this given timeout no devices responded or that effectively no devices are available at all.
        Throws:
        java.io.IOException - if some IOException occurs during discovering
      • discover

        public static RootDevice[] discover​(int timeOut,
                                            int ttl,
                                            int mx,
                                            java.lang.String searchTarget)
                                     throws java.io.IOException
        Devices discovering on all network interfaces with a given timeout and a given root device to search, as well as a ttl and mx param
        Parameters:
        timeOut - the timeout for the a device to give a reponse
        ttl - the UDP socket packets time to live
        mx - discovery message mx http header field value
        searchTarget - the device URI to search
        Returns:
        an array of UPNP Root device that matches the search or null if nothing found within the given timeout. Null return does NOT means that no UPNP device is available on the network. It only means that for this given timeout no devices responded or that effectively no devices are available at all.
        Throws:
        java.io.IOException - if some IOException occurs during discovering
      • discover

        public static RootDevice[] discover​(int timeOut,
                                            int ttl,
                                            int mx,
                                            java.lang.String searchTarget,
                                            java.net.NetworkInterface ni)
                                     throws java.io.IOException
        Devices discovering with a given timeout and a given root device to search on an given network interface, as well as a ttl and mx param
        Parameters:
        timeOut - the timeout for the a device to give a reponse
        ttl - the UDP socket packets time to live
        mx - discovery message mx http header field value
        searchTarget - the device URI to search
        ni - the networkInterface where to search devices, null to lookup all interfaces
        Returns:
        an array of UPNP Root device that matches the search or null if nothing found within the given timeout. Null return does NOT means that no UPNP device is available on the network. It only means that for this given timeout no devices responded or that effectively no devices are available at all.
        Throws:
        java.io.IOException - if some IOException occurs during discovering
      • sendSearchMessage

        public static void sendSearchMessage​(java.net.InetAddress src,
                                             int ttl,
                                             int mx,
                                             java.lang.String searchTarget)
                                      throws java.io.IOException
        Sends an SSDP search message on the network
        Parameters:
        src - the sender ip
        ttl - the time to live
        mx - the mx field
        searchTarget - the search target
        Throws:
        java.io.IOException - if some IO errors occurs during search