title: SSDP Search in Windows Phone 8
body: <p>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.</p>
  
  <p>Using this <a href="http://www.windowsphone.com/s?appid=934168d7-f476-40a6-a42b-e0f4a56dae84" rel="nofollow">SSDP Sniffer</a> app, I get a lot of results so I'm attempting to recreate this.</p>
  
  <p>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.</p>
  
  <p>thanks!</p>
  
  <pre><code>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) =&gt;
      {
          // This is invoked for each device that responds to the query...
          Task.Run(() =&gt;
              {
                   // 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);
  }
  </code></pre>