Yortw / RSSDP

Really Simple Service Discovery Protocol - a 100% .Net implementation of the SSDP protocol for publishing custom/basic devices, and discovering all device types on a network.
http://yortw.github.io/RSSDP/
MIT License
282 stars 66 forks source link

Net able to get location from fullDevice #88

Closed tommykjensen closed 3 years ago

tommykjensen commented 5 years ago

I have added the simple search example to a project and when run it devices are found.

But I am not able to access location in fullDevice in order to get to the IP address.

This line works

Console.WriteLine(fullDevice.FriendlyName);

but intellisense will not give me location so I can get to host

Console.WriteLine(fullDevice.Location);

but in debug I can see Location and within that I can see Host.

I am trying to build a list of Heos devices with their IP addresses.

image

winkmichael commented 5 years ago

I have this same issue, did you make any progress on this one?

Thank you very much

winkmichael commented 5 years ago

I did find a really budget work around to get the IP;

Console.WriteLine(foundDevice.DescriptionLocation.ToString());

Will spit you out the URL to the description file.

http://192.168.1.225:32469/DeviceDescription.xml

You can then parse that to get the IP, not ideal, but since I am on a schedule a work around that I can use for now.

Yortw commented 5 years ago

Hi,

Sorry it's taken me so long to get to this. I'm at work at the moment and so will have to find time to make any mods, and I'm not quite sure what to do. Changing the existing property would be a breaking change, and MS guidance is not to store url's as strings anyway (hence the use of System.Uri). I guess I could add a second property, just need to figure out what the name should be. Frustrating that the device requires the default port to be specified, I don't think that's spec compliant, but it is what it is either way.

As for work arounds, if what you want is to get the IP/Host name out of the url, you should be able to use;

foundDevice.DescriptionLocation.Host

for just the ip/host name or

foundDevice.DescriptionLocation.Authority

for host name and port (if port isn't the default port for the protocol, otherwise this just returns the ip/host name again).

You could possibly rebuild the url string yourself (I know this is not ideal); Something like this should work;

            var s = deviceLocation.Scheme + "://";
            if (deviceLocation.Authority == deviceLocation.Host)
            {
                if (deviceLocation.Scheme == Uri.UriSchemeHttp)
                    s = s += deviceLocation.Host + ":80";
                else if (deviceLocation.Scheme == Uri.UriSchemeHttps)
                    s = s += deviceLocation.Host + ":443";
            }
            else
                s += deviceLocation.Authority;

            s += deviceLocation.PathAndQuery;
            Console.WriteLine(s);
Yortw commented 5 years ago

Actually, I just remembered, all of this is unnecessary. You should be able to get the original string from the Uri property already;

    var urlStr = foundDevice.DescriptionLocation.OriginalString;

That should return the original string, including the port. Use that instead of .ToString() and you should be good. Please let me know if this is not the case.

Yortw commented 5 years ago

Sorry, comments above were replies to another issue, I must have clicked the wrong link or something.

I am not sure why intellisense is not showing you the Location property, especially since the debugger can see it. Does it matter? If you write the code to use the location property without the help of intellisense will the code compile and run? (i.e it may just be an intellisense issue).

Alternatively, under Tools -> Options and then, Text Editor -> C# there is an option 'hide advanced members'. Maybe try turning that off, as I think it is on (or partially on) by default, and it specifically hides some things from intellisense (even though they are still usable, it just won't prompt for them). Possibly that is your problem?

winkmichael commented 5 years ago

Thank you very much for this Yortw, this has me setup just perfect. Awesome lib you got. Thanks again.

Yortw commented 5 years ago

Glad to hear it, and thanks for the kind words :)

@tommykjensen does this solve your issue too?

SiyerBOBO commented 3 years ago

Excuse me, How do I fill in my XML address? Is the XML file to be pre-published to the LAN? How to publish it? What should I do if I have an a.xml file under the D disk path? Thank you. @Tapanila @kakone @martinwiboe @LukePulverenti @jay18001

Yortw commented 3 years ago

@SiyerBOBO You probably should create a new issue for this. However, in short, what you need to do is create an SsdpRootDevice, fill in the properties and then add it to an instance of SsdpDevicePublisher. The SsdpRootDevice includes a property for your to specify the 'base address' which is the path your HTTP server uses to serve the XML document, or you can call methods on the SsdpDevicePublisher instance to create the XML for you if yor prefer.

When you create the SsdpPublisher instance you can pass in an ip address and that will be the address the publisher responds to search requests on (and broadcasts notifications). Make sure that address matches whatever is in the XML your serve.