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.

Home Page:http://yortw.github.io/RSSDP/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Location string missing default port.

Frankenslag opened this issue · comments

I have an issue using RSSDP with an Amazon Echo device (I am trying to emulate a Philips Hue Bridge to work with Alexa). The Echo seems to need the location port explicitly stated (i.e. http://192.168.1.32:80/description.xml comes out as http://192.168.1.32/description.xml) and the Uri ToString() method removes the default port. Can I suggest an option to output the original string from the Uri rather than as currently happens.

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.

Thanks for your reply but at the moment the code at line 568 of SsdpDevicePublisherBase.cs specifies rootDevice.Location as a parameter for formatting the SSDP response string. I have worked my way round this by subclassing Uri and overriding the ToString method as follows and use that to pass the location to the SsdpRootDevice.

    private class LocationUri : Uri
    {
        public LocationUri(Uri baseUri, string relativeUri) : base(baseUri, relativeUri)
        {

        }

        public override string ToString()
        {
            return (IsDefaultPort ? $" {Scheme}://{Host}:{Port.ToString()}{this.LocalPath}" : base.ToString());
        }

    }