コード例 #1
0
        private async void SendSearchResponse(string searchTarget, SsdpDevice device, string uniqueServiceName, IpEndPointInfo endPoint, IpAddressInfo receivedOnlocalIpAddress)
        {
            var rootDevice = device.ToRootDevice();

            //var additionalheaders = FormatCustomHeadersForResponse(device);

            const string header = "HTTP/1.1 200 OK";

            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            values["EXT"]           = "";
            values["DATE"]          = DateTime.UtcNow.ToString("r");
            values["CACHE-CONTROL"] = "max-age = 600";
            values["ST"]            = searchTarget;
            values["SERVER"]        = string.Format("{0}/{1} UPnP/1.0 RSSDP/{2}", _OSName, _OSVersion, ServerVersion);
            values["USN"]           = uniqueServiceName;
            values["LOCATION"]      = rootDevice.Location.ToString();

            var message = SsdpHelper.BuildMessage(header, values);

            try
            {
                await _CommsServer.SendMessage(System.Text.Encoding.UTF8.GetBytes(message), endPoint, receivedOnlocalIpAddress).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
            }

            //WriteTrace(String.Format("Sent search response to " + endPoint.ToString()), device);
        }
コード例 #2
0
        private Task SendByeByeNotification(SsdpDevice device, string notificationType, string uniqueServiceName)
        {
            const string header = "NOTIFY * HTTP/1.1";

            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // If needed later for non-server devices, these headers will need to be dynamic
            values["HOST"]   = "239.255.255.250:1900";
            values["DATE"]   = DateTime.UtcNow.ToString("r");
            values["SERVER"] = string.Format("{0}/{1} UPnP/1.0 RSSDP/{2}", _OSName, _OSVersion, ServerVersion);
            values["NTS"]    = "ssdp:byebye";
            values["NT"]     = notificationType;
            values["USN"]    = uniqueServiceName;

            var message = SsdpHelper.BuildMessage(header, values);

            return(_CommsServer.SendMulticastMessage(message));

            //WriteTrace(String.Format("Sent byebye notification"), device);
        }
コード例 #3
0
        private Task BroadcastDiscoverMessage(string serviceType, TimeSpan mxValue)
        {
            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            values["HOST"]       = "239.255.255.250:1900";
            values["USER-AGENT"] = "UPnP/1.0 DLNADOC/1.50 Platinum/1.0.4.2";
            //values["X-EMBY-SERVERID"] = _appHost.SystemId;

            values["MAN"] = "\"ssdp:discover\"";

            // Search target
            values["ST"] = "ssdp:all";

            // Seconds to delay response
            values["MX"] = "3";

            var header = "M-SEARCH * HTTP/1.1";

            var message = SsdpHelper.BuildMessage(header, values);

            return(_CommunicationsServer.SendMulticastMessage(message));
        }
コード例 #4
0
        private void SendAliveNotification(SsdpDevice device, string notificationType, string uniqueServiceName)
        {
            var rootDevice = device.ToRootDevice();

            const string header = "NOTIFY * HTTP/1.1";

            var values = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // If needed later for non-server devices, these headers will need to be dynamic
            values["HOST"]          = "239.255.255.250:1900";
            values["DATE"]          = DateTime.UtcNow.ToString("r");
            values["CACHE-CONTROL"] = "max-age = " + rootDevice.CacheLifetime.TotalSeconds;
            values["LOCATION"]      = rootDevice.Location.ToString();
            values["SERVER"]        = string.Format("{0}/{1} UPnP/1.0 RSSDP/{2}", _OSName, _OSVersion, ServerVersion);
            values["NTS"]           = "ssdp:alive";
            values["NT"]            = notificationType;
            values["USN"]           = uniqueServiceName;

            var message = SsdpHelper.BuildMessage(header, values);

            _CommsServer.SendMulticastMessage(message);

            //WriteTrace(String.Format("Sent alive notification"), device);
        }