4

Working on an appliance and would like to support zero configuration feature. That way users can look for the device on the network and simply double click an icon to access the web interface without having to configure it or know its ip address.

Tried to use UPNPLib_TLB but functions seem to be read-only; am I right? I can create a device using CoUPnPDevice.Create but can't set a FriendlyName or a URL.

Tried to use Deltics Bonjour service but it crashes on create (ACCESS_VIOLATION). The demo code uses a custom test unit which complicates experimentation.

After much research it does not look like there is a component available for this and would appreciate some pointers. Has anyone successfully created a zeroconf broadcast either via UPnP or Bonjour with Delphi XE2/5.. I can go back to Delphi 7 if required. Target = Windows 7.

NOTE: To be clear, I can find existing devices on the network and don't want to enumerate existing devices but what I want is to broadcast my service so that my box behaves like a network printer for example. The only service I need to expose is the URL so that users can access an embedded web server.

Appreciate the help!

EDIT With the tips provided I did some research and getting this done the RAD way is not possible.

Using MS APIs directly is time consuming and requires a level of understanding of C that I don't have. Porting the Delphi 5/Indy 7 component to XE2/5 will require a good amount of work and debugging.

I discovered UPnP developer tools from Intel now open source here: Developer Tools for UPnP. This tools makes it really simply to create a server in 10-15 lines of code. Intel provides a DLL that I can call from VS Express as follows and it works great:

device = UPnPDevice.CreateRootDevice();
device.FriendlyName = 'My name';
device.PresentationURL = 'URLToEmbeddedServer";

..

I tried to use headconv7 tool to convert the .h file Intel's UPNP.DLL to a pascal file and call the external functions within the DLL directly from Delphi but there were too many problems with the conversion.

It's too bad because the Intel library makes it really simple to create UPnP stacks and the approach would apply itself very well to a component but for now its quicker to use .NET and VS Express to get the job done.

mghie
  • 32,028
  • 6
  • 87
  • 129
Alain Thiffault
  • 608
  • 3
  • 13
  • You saw [this answer](http://stackoverflow.com/a/15532220) related to UPNP, particularly the link to François Piette's article? – Ken White Apr 18 '14 at 19:13
  • Thanks; I experimented with UPNPLib_TLB using François Piette's UpnPFinderDemo. Listing existing devices on the network works well. Its creating a service that does not work (or I didn't find how) – Alain Thiffault Apr 18 '14 at 21:10
  • Have a look at http://mikejustin.wordpress.com/2013/07/07/discover-activemq-brokers-with-delphi-xe4-and-indy-10-6/ Based on that it is very easy to build the sending part – Sir Rufo Apr 18 '14 at 21:11
  • I also looked at the Whitebear components but they are very old and don't work in XE2-XE5. I have D7 somewhere and will try to install that again during the weekend to test. I will also try to port to XE2 but there are quite a bit of changes required I think. – Alain Thiffault Apr 18 '14 at 21:12

1 Answers1

1

When using UPNPLib_TLB, you are not supposed to create a UPnPDevice object directly. UPnpDevice describes a known device on the network, which is why its properties are read-only.

Read the documentation:

Control Point API

Finding Devices

You are supposed to create an instance of the UPnPDeviceFinder class instead. Its search methods will give you a UPnDevice object for each device that is found.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Yes, got the finding part and it works but I'm looking for the inverse; to respond to UPnPDeviceFinder. I need some sort of a service that responds to UDP broadcasts from this call; is that a better way of explaining what I what to do? Maybe there's something I'n not understanding on how this "handshaking" works. – Alain Thiffault Apr 18 '14 at 21:30
  • 1
    To create a device that `UPnpDeviceFinder` (or any other uPNP library) can find, your app can implement a [`Hosted Device`](http://msdn.microsoft.com/en-us/library/windows/desktop/aa381164.aspx) and let Windows handle the protocol details for you. – Remy Lebeau Apr 18 '14 at 22:35
  • Currently looking into using the UPnP Windows API directly (which isn't very RAD) as well as porting the Whitebear Delphi 5 component. I'll post back my findings shortly. – Alain Thiffault Apr 22 '14 at 19:26