locked
UPnP and stale devices RRS feed

  • Question

  • I posted this in another forum and it was suggested that I repost here.

    I am using the Interop.UPNPLib and C# to create a control point  and I am finding that when a device disappears from the network (i.e. power outage/brown out) that the async interface to IUPnPDeviceFinder doesn't tell me first that the device was removed, and second that it was added after it comes back.

    Using the control point API from windows UPNPLib, and also by observation through My Network Places, if a device sends a NOTIFY with "NTS: ssdp:alive" the device appears at the device added control point API and in My Network Places.  If that device sends a NOTIFY with "NTS: ssdp:byebye" the device removed control point API is notified and the device disappears from My Network Places and the UPnP device cache.

    However, if the NOTIFY with "NTS: ssdp:byebye" does not get to the windows UPnP stack, or if the device doesn't send one (power outage, network outage, not implemented, etc.) the device is not removed from the cache, it stays in My Network Places and additional calls from the control point API show the device.  I assume that the device would disappear after the cache timeout for the device expires but since this time is generally 30 minutes or greater it could be a very long time before the device is removed.

    An additional unfortunate side affect is that when the device comes back the async finder interface of the control point API does not get called back when the device reappears.

    The implications are that when a device disappears from the network, my control point code tries to reach the device and times out because it is not there.  If my control point caches the device as not really there I can avoid additional attempts to connect but at a cost of not being able to see it if the device reappears.

    I did notice that if I try to invoke the device from My Network Places that a missing device will sometimes be removed from the display prior to the cache timeout but when I make the device reappear the async control point still does not get called back even though the device then reappears in My Network Places.

    I have not found any interfaces in UPNPLib to clear the cache and the UPNPHostLib interfaces appear to only operate on devices created on that host so the registrar interface does not work. 

    Is there some way to get the async control point IUPnPDeviceFinder interface to receive a callback when a device goes away and then comes back?  Perhaps some registry settings?

     Jeff

    • Moved by Jesse Jiang Friday, February 18, 2011 10:41 AM (From:Visual Studio Smart Device Development – Visual Basic and C# Projects)
    Wednesday, February 16, 2011 1:08 PM

Answers

All replies

  • Here is a little better definition of the problem.

    Using C#, I have a class that extends IUPnPDeviceFinderCallback that implements DeviceAddedEventHandler, DeviceRemovedEventHandler, and SearchCompletedEventHandler and has a Start() method that performs the following:

    UPnPDeviceFinderClass finder = new UPnPDeviceFinderClass();
    searchId = finder.CreateAsyncFind(“upnp:rootdevice”, 0, this);
    finder.StartAsyncFind(searchId);

    When I instantiate and call the Start()  method of my class I receive calls at the added, removed, and search complete interfaces.  Even after the search complete interface has been called I continue to see newly discovered devices through the DeviceAddedEventHandler as well as devices that leave using the byebye NOTIFY at the DeviceRemovedEventHandler.  I like this as it means I don’t need to cancel and restart the async find to see new devices coming and going in the network.

    However, if a device that has been seen once goes away (power failure, etc.) and then comes back and does another NOTIFY, the new notification does not result in a call to the DeviceAddedEventHandler.  As such, I do not have a means of knowing that the device has recovered unless I poll it.

    I can essentially poll it by using a UPnPDeviceFinderClass and either doing a broad search or a specific UDN search.  If the device has recovered, the new search will return the device but the previously instantiated UPnPDeviceFinderClass that is doing the async find will still not see that the device is back.

    This seems like the finder class might be caching the notion that it has already “added” the device so it doesn’t call the DeviceAddedEventHandler for it again.  If so, is there any way to clear that device from its cache?

    One other odd thing is that if I cancel the previous find and issue a new async find before the device has recovered I still do not get a device added callback when it recovers.  That implies I really need to enter a continuous polling method to be able to see the recovered device.  Not good.

    Jeff

    Thursday, February 17, 2011 1:10 PM
  • Try http://social.msdn.microsoft.com/Forums/en-US/wdk/threads

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Monday, February 21, 2011 10:13 PM