0

I am using the Cling Java library to implement a UPnP control point.

The native controlpoint.search() function is non-blocking and reports devices through a callback mechanism.

Is there a way to make a blocking call to search, which returns when device(s) are found? Or a status flag on which I can wait until a device is found?

(It is trivial to implement this on my own, but I would like to use the native API as much as possible)

Community
  • 1
  • 1
schinoy
  • 115
  • 1
  • 1
  • 7
  • For a general way to do with, look at http://stackoverflow.com/q/4639853/116509, but Pavel's answer is important – artbristol Nov 01 '12 at 09:17

1 Answers1

3

Even if the API would allow it (it doesn't), it would be very unwise thing to do. Device discovery (aka search) in UPnP is inherently asynchronous. The search starts with a broadcast, and you as the control point can't know when the devices will respond, how many there will be, and if any at all. There is no such event in UPnP discovery as "now i found all devices and there won't be any more" - which is exactly what you would need to have in order for reliable blocking wait. The best compromise could be a blocking wait with a timeout - but what timeout you would set? Too short means that some device may fail to respond in time (your privately decided time), too long means that you would be still waiting even if there are no more devices to respond - but due to design of UPnP ad-hoc network, you simply can't know how many devices are out there.

You perhaps need to explain why a blocking search is so important for you.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38