Beispiel #1
0
 private ReceivedUdpData GetMockSearchResponse(SsdpDevice device, string stHeader)
 {
     return GetMockSearchResponseWithCustomCacheHeader(device, stHeader, String.Format("CACHE-CONTROL: public, max-age={0}", device.ToRootDevice().CacheLifetime.TotalSeconds));
 }
Beispiel #2
0
        private ReceivedUdpData GetMockSearchResponseWithCustomCacheHeader(SsdpDevice device, string stHeader, string cacheHeader)
        {
            var responseText = String.Format(@"HTTP/1.1 200 OK
            EXT:
            DATE: {4}{0}
            ST:{1}
            SERVER: TestOS/1.0 UPnP/1.0 RSSDP/1.0
            USN:{2}
            LOCATION:{3}

            ", //Blank line at end important, do not remove.
             String.IsNullOrEmpty(cacheHeader) ? String.Empty : Environment.NewLine + cacheHeader,
             stHeader,
             String.Format("{0}:{1}", device.Udn, device.FullDeviceType),
             device.ToRootDevice().Location,
             DateTime.UtcNow.ToString("r")
             );

            var retVal = new ReceivedUdpData()
            {
                Buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(responseText),
                ReceivedFrom = new UdpEndPoint() { IPAddress = SsdpConstants.MulticastLocalAdminAddress, Port = SsdpConstants.MulticastPort }
            };
            retVal.ReceivedBytes = retVal.Buffer.Length;

            return retVal;
        }
Beispiel #3
0
        private ReceivedUdpData GetMockAliveNotification(SsdpDevice device)
        {
            var rootDevice = device.ToRootDevice();

            var data = String.Format(@"NOTIFY * HTTP/1.1
            HOST: 239.255.255.250:1900
            Date: {0}
            NT: {1}
            NTS: ssdp:alive
            SERVER: TestOS/1.0 UPnP/1.0 RSSDP/1.0
            USN: {2}
            LOCATION: {3}
            CACHE-CONTROL: public, max-age={4}

            ",
            DateTime.UtcNow.ToString("r"),
            device.Udn,
            String.Format("{0}::{1}", device.Udn, device.FullDeviceType),
            rootDevice.Location,
            rootDevice.CacheLifetime.TotalSeconds
             );

            var retVal = new ReceivedUdpData()
            {
                Buffer = System.Text.UTF8Encoding.UTF8.GetBytes(data),
                ReceivedFrom = new UdpEndPoint()
                {
                    IPAddress = SsdpConstants.MulticastLocalAdminAddress,
                    Port = 1900
                }
            };
            retVal.ReceivedBytes = retVal.Buffer.Length;

            return retVal;
        }