/// <summary>
        /// Parses the HTTP request out of the given <paramref name="stream"/>.
        /// </summary>
        /// <param name="stream">HTTP data stream to parse.</param>
        /// <param name="result">Returns the parsed HTTP response instance.</param>
        /// <exception cref="MediaPortal.Utilities.Exceptions.InvalidDataException">If the given <paramref name="stream"/> is malformed.</exception>
        public static void Parse(Stream stream, out SimpleHTTPResponse result)
        {
            result = new SimpleHTTPResponse();
            string firstLine;

            result.ParseHeaderAndBody(stream, out firstLine);
            string[] elements = firstLine.Split(' ');
            if (elements.Length != 3)
            {
                throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
            }
            string httpVersion = elements[0];

            if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1")
            {
                throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
            }
            int code;

            if (!int.TryParse(elements[1], out code))
            {
                throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
            }
            result._code = (HTTPResponseCode)code;
        }
    public void SendMessage(string NT, string USN, DvDevice rootDevice)
    {
      SimpleHTTPResponse response = new SimpleHTTPResponse(HTTPResponseCode.Ok);
      response.SetHeader("CACHE-CONTROL", "max-age = " + _serverData.AdvertisementExpirationTime);
      response.SetHeader("DATE", DateTime.Now.ToUniversalTime().ToString("R"));
      response.SetHeader("EXT", string.Empty);
      response.SetHeader("SERVER", UPnPConfiguration.UPnPMachineInfoHeader);
      response.SetHeader("ST", NT);
      response.SetHeader("USN", USN);
      response.SetHeader("BOOTID.UPNP.ORG", _serverData.BootId.ToString());
      response.SetHeader("CONFIGID.UPNP.ORG", _localEndpointConfiguration.ConfigId.ToString());
      if (_localEndpointConfiguration.AddressFamily == AddressFamily.InterNetworkV6)
      {
        response.SetHeader("OPT", "\"http://schemas.upnp.org/upnp/1/0/\"; ns=01");
        response.SetHeader("01-NLS", _serverData.BootId.ToString());
      }
      if (_localEndpointConfiguration.SSDPUsesSpecialSearchPort)
        response.SetHeader("SEARCHPORT.UPNP.ORG", _localEndpointConfiguration.SSDPSearchPort.ToString());

      response.SetHeader("LOCATION", _localEndpointConfiguration.GetRootDeviceDescriptionURL(rootDevice));
      byte[] bytes = response.Encode();
      Socket socket = _localEndpointConfiguration.SSDP_UDP_UnicastSocket;
      if (socket != null)
        NetworkHelper.SendData(socket, _receiverEndPoint, bytes, 1);
    }
 protected void HandleSSDPResponse(SimpleHTTPResponse header, EndpointConfiguration config, IPEndPoint remoteEndPoint)
 {
   HTTPVersion httpVersion;
   if (!HTTPVersion.TryParse(header.HttpVersion, out httpVersion))
     // Invalid response
     return;
   string cacheControl = header["CACHE-CONTROL"];
   string date = header["DATE"];
   // EXT is not used
   //string ext = header["EXT"];
   string location = header["LOCATION"];
   string server = header["SERVER"];
   // ST is not used
   //string st = header["ST"];
   string usn = header["USN"];
   string bi = header["BOOTID.UPNP.ORG"];
   string ci = header["CONFIGID.UPNP.ORG"];
   string sp = header["SEARCHPORT.UPNP.ORG"];
   HandleNotifyPacket(config, remoteEndPoint, httpVersion, date, cacheControl, location, server, "ssdp:alive", usn, bi, ci, sp);
 }
 /// <summary>
 /// Parses the HTTP request out of the given <paramref name="stream"/>.
 /// </summary>
 /// <param name="stream">HTTP data stream to parse.</param>
 /// <param name="result">Returns the parsed HTTP response instance.</param>
 /// <exception cref="MediaPortal.Utilities.Exceptions.InvalidDataException">If the given <paramref name="stream"/> is malformed.</exception>
 public static void Parse(Stream stream, out SimpleHTTPResponse result)
 {
   result = new SimpleHTTPResponse();
   string firstLine;
   result.ParseHeaderAndBody(stream, out firstLine);
   string[] elements = firstLine.Split(' ');
   if (elements.Length != 3)
     throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
   string httpVersion = elements[0];
   if (httpVersion != "HTTP/1.0" && httpVersion != "HTTP/1.1")
     throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
   int code;
   if (!int.TryParse(elements[1], out code))
     throw new InvalidDataException("Invalid HTTP request header starting line '{0}'", firstLine);
   result._code = (HTTPResponseCode) code;
 }