SSDP Search in Windows Phone 8

被刻印的时光 ゝ 提交于 2019-12-23 02:16:43

问题


I'm new at SSDP/UPNP/Sockets and all that jazz. I'm playing around with it a bit and I just want to see what a generic SSDP search on my network will bring up.

Using this SSDP Sniffer app, I get a lot of results so I'm attempting to recreate this.

I'm using the following code, which I've found various versions of, but all the tweaking I do doesn't appear to bring back any results. I pretty much at a loss here and would appreciate any guidance.

thanks!

private const string SSDP_IP = "239.255.255.250";
private const string SSDP_PORT = "1900";
private const string SSDP_QUERY = "M-SEARCH * HTTP/1.1\r\n" +
                                  "Host: " + SSDP_IP + ":" + SSDP_PORT + "\r\n" +
                                  "Man: ssdp:discover\r\n" +
                                  "ST: ssdp:all\r\n";

DataGramSocket socket;

async public void SsdpQueryAsync()
{
    var remoteIP = new Windows.Networking.HostName(SSDP_IP);
    var reqBuff = Encoding.UTF8.GetBytes(SSDP_QUERY);

    socket = new DatagramSocket();

    socket.MessageReceived += (sender, args) =>
    {
        // This is invoked for each device that responds to the query...
        Task.Run(() =>
            {
                 // do something useful
            });
    };

    await socket.BindEndpointAsync(null, "");

    socket.JoinMulticastGroup(remoteIP);

    using (var stream = await socket.GetOutputStreamAsync(remoteIP, SSDP_PORT))
    {
        await stream.WriteAsync(reqBuff.AsBuffer());
    }

    await Task.Delay(5000);
}

回答1:


I'm not familiar with C# or dotnet APIs, but I can see some details wrong with the M-SEARCH message:

  • MAN header must be enclosed in double quotes, so MAN: "ssdp:discover"\r\n
  • MX header is missing (required for multicast)
  • USER-AGENT header is missing
  • missing an empty line in the end
  • Header names are supposedly case insensitive, but I'd use upper case just in case...

See the Device Architecture reference pdf for more details



来源:https://stackoverflow.com/questions/18834893/ssdp-search-in-windows-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!