public void SendMessage(string NT, string USN, DvDevice rootDevice)
    {
      SimpleHTTPResponse response = new SimpleHTTPResponse(HTTPResponseCode.Ok);
      response.SetHeader("CACHE-CONTROL", "max-age = " + _serverData.AdvertisementExpirationTime);
      response.SetHeader("DATE", DateTime.Now.ToUniversalTime().ToString("R"));
      response.SetHeader("EXT", string.Empty);
      response.SetHeader("SERVER", UPnPConfiguration.UPnPMachineInfoHeader);
      response.SetHeader("ST", NT);
      response.SetHeader("USN", USN);
      response.SetHeader("BOOTID.UPNP.ORG", _serverData.BootId.ToString());
      response.SetHeader("CONFIGID.UPNP.ORG", _localEndpointConfiguration.ConfigId.ToString());
      if (_localEndpointConfiguration.AddressFamily == AddressFamily.InterNetworkV6)
      {
        response.SetHeader("OPT", "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01");
        response.SetHeader("01-NLS", _serverData.BootId.ToString());
      }
      if (_localEndpointConfiguration.SSDPUsesSpecialSearchPort)
        response.SetHeader("SEARCHPORT.UPNP.ORG", _localEndpointConfiguration.SSDPSearchPort.ToString());

      response.SetHeader("LOCATION", _localEndpointConfiguration.GetRootDeviceDescriptionURL(rootDevice));
      byte[] bytes = response.Encode();
      Socket socket = _localEndpointConfiguration.SSDP_UDP_UnicastSocket;
      if (socket != null)
        NetworkHelper.SendData(socket, _receiverEndPoint, bytes, 1);
    }
Пример #2
0
    /// <summary>
    /// Sends a NOTIFY packet "ssdp:update" to all UPnP endpoints.
    /// </summary>
    /// <param name="NT">Notification type.</param>
    /// <param name="USN">Unique Service Name.</param>
    /// <param name="rootDevice">Root device for that the message should be send.</param>
    public void SendMessage(string NT, string USN, DvDevice rootDevice)
    {
      SimpleHTTPRequest response = new SimpleHTTPRequest("NOTIFY", "*");
      response.SetHeader("NT", NT);
      response.SetHeader("NTS", "ssdp:update");
      response.SetHeader("USN", USN);
      response.SetHeader("BOOTID.UPNP.ORG", _lastBootId.ToString());
      response.SetHeader("NEXTBOOTID.UPNP.ORG", _nextBootId.ToString());
      // Currently, we don't support SEARCHPORT.UPNP.ORG function and header

      foreach (EndpointConfiguration config in _serverData.UPnPEndPoints)
      {
        if (config.AddressFamily == AddressFamily.InterNetworkV6)
        {
          response.SetHeader("OPT", "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01");
          response.SetHeader("01-NLS", _serverData.BootId.ToString());
        }
        response.SetHeader("CONFIGID.UPNP.ORG", config.ConfigId.ToString());
        IPEndPoint ep = new IPEndPoint(config.SSDPMulticastAddress, UPnPConsts.SSDP_MULTICAST_PORT);
        response.SetHeader("HOST", NetworkHelper.IPEndPointToString(ep));
        if (config.SSDPUsesSpecialSearchPort)
          response.SetHeader("SEARCHPORT.UPNP.ORG", config.SSDPSearchPort.ToString());
        response.SetHeader("LOCATION", config.GetRootDeviceDescriptionURL(rootDevice));
        byte[] bytes = response.Encode();
        NetworkHelper.MulticastMessage(config.SSDP_UDP_UnicastSocket, config.SSDPMulticastAddress, bytes);
      }
    }
 protected static void SendMessagesServices(DvDevice rootDevice, DvDevice device, ISSDPDiscoveryMessageSender messageSender)
 {
   ICollection<string> services = device.GetServiceTypeVersion_URNs();
   foreach (string serviceTypeVersion_URN in services)
       // One notification for each service
     SendMessagesService(rootDevice, device, serviceTypeVersion_URN, messageSender);
 }
 protected static void SendMessagesEmbeddedDevicesRecursive(DvDevice rootDevice, DvDevice device, ISSDPDiscoveryMessageSender messageSender)
 {
   SendMessagesEmbeddedDevice(rootDevice, device, messageSender);
   SendMessagesServices(rootDevice, device, messageSender);
   foreach (DvDevice embeddedDevice in device.EmbeddedDevices)
     SendMessagesEmbeddedDevicesRecursive(rootDevice, embeddedDevice, messageSender);
 }
 protected static void SendMessagesRootDevice(DvDevice rootDevice, ISSDPDiscoveryMessageSender messageSender)
 {
   string deviceUDN = rootDevice.UDN;
   messageSender.SendMessage("upnp:rootdevice", deviceUDN + "::upnp:rootdevice", rootDevice);
   messageSender.SendMessage(deviceUDN, deviceUDN, rootDevice);
   messageSender.SendMessage(rootDevice.DeviceTypeVersion_URN, deviceUDN + "::" + rootDevice.DeviceTypeVersion_URN, rootDevice);
   SendMessagesServices(rootDevice, rootDevice, messageSender);
   foreach (DvDevice embeddedDevice in rootDevice.EmbeddedDevices)
     SendMessagesEmbeddedDevicesRecursive(rootDevice, embeddedDevice, messageSender);
 }
Пример #6
0
 /// <summary>
 /// Adds the specified embedded <paramref name="device"/>.
 /// </summary>
 /// <remarks>
 /// Should be done at the time when the UPnP system is not bound to the network yet, but if the binding is already
 /// established, the system will notify a configuration update.
 /// Note that default devices (defined by a UPnP Forum working committee) must be added first.
 /// </remarks>
 /// <param name="device">Device to add to the embedded devices.</param>
 public void AddEmbeddedDevice(DvDevice device)
 {
     device.ParentDevice = this;
     _embeddedDevices.Add(device);
 }
Пример #7
0
 /// <summary>
 /// Adds a new UPnP root device. Should be done before <see cref="Bind"/> is called.
 /// </summary>
 /// <param name="device">Device to add to the <see cref="RootDevices"/> collection.</param>
 public void AddRootDevice(DvDevice device)
 {
   _rootDevices.Add(device);
 }
Пример #8
0
 /// <summary>
 /// Returns an URL which points to the root device description of the given <paramref name="rootDevice"/> on this endpoint.
 /// </summary>
 /// <param name="rootDevice">Root device to get the description URL for.</param>
 /// <returns>Absolute URL to the device description.</returns>
 public string GetRootDeviceDescriptionURL(DvDevice rootDevice)
 {
   return GetEndpointHttpPrefixString() + _rootDeviceDescriptionPaths[rootDevice];
 }
Пример #9
0
 /// <summary>
 /// Adds the specified embedded <paramref name="device"/>.
 /// </summary>
 /// <remarks>
 /// Should be done at the time when the UPnP system is not bound to the network yet, but if the binding is already
 /// established, the system will notify a configuration update.
 /// Note that default devices (defined by a UPnP Forum working committee) must be added first.
 /// </remarks>
 /// <param name="device">Device to add to the embedded devices.</param>
 public void AddEmbeddedDevice(DvDevice device)
 {
   device.ParentDevice = this;
   _embeddedDevices.Add(device);
 }
 protected static void SendMessagesService(DvDevice rootDevice, DvDevice device, string serviceTypeVersion_URN,
     ISSDPDiscoveryMessageSender messageSender)
 {
   string deviceUUID = device.UDN;
   messageSender.SendMessage(serviceTypeVersion_URN, deviceUUID + "::" + serviceTypeVersion_URN, rootDevice);
 }
 protected static void SendMessagesEmbeddedDevice(DvDevice rootDevice, DvDevice device, ISSDPDiscoveryMessageSender messageSender)
 {
   string deviceUDN = device.UDN;
   messageSender.SendMessage(deviceUDN, deviceUDN, rootDevice);
   messageSender.SendMessage(device.DeviceTypeVersion_URN, deviceUDN + "::" + device.DeviceTypeVersion_URN, rootDevice);
 }