示例#1
0
文件: UdpServer.cs 项目: t-andre/Emby
        private async Task RespondToV2Message(string messageText, string endpoint, Encoding encoding)
        {
            var parts = messageText.Split('|');

            var localUrl = await _appHost.GetLocalApiUrl().ConfigureAwait(false);

            if (!string.IsNullOrEmpty(localUrl))
            {
                var response = new ServerDiscoveryInfo
                {
                    Address = localUrl,
                    Id = _appHost.SystemId,
                    Name = _appHost.FriendlyName
                };

                await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint).ConfigureAwait(false);
                
                if (parts.Length > 1)
                {
                    _appHost.EnableLoopback(parts[1]);
                }
            }
            else
            {
                _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
            }
        }
示例#2
0
        private async void RespondToV2Message(string endpoint)
        {
            var localAddress = GetLocalIpAddress();

            if (!string.IsNullOrEmpty(localAddress))
            {
                var serverAddress = string.Format("http://{0}:{1}", localAddress, _serverConfigurationManager.Configuration.HttpServerPortNumber);

                var response = new ServerDiscoveryInfo
                {
                    Address = serverAddress,
                    Id = _appHost.ServerId,
                    Name = _appHost.FriendlyName
                };

                await SendAsync(Encoding.UTF8.GetBytes(_json.SerializeToString(response)), endpoint);
            }
            else
            {
                _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
            }
        }
示例#3
0
        private async void RespondToV2Message(string endpoint, Encoding encoding)
        {
            var localUrl = _appHost.LocalApiUrl;

            if (!string.IsNullOrEmpty(localUrl))
            {
                var response = new ServerDiscoveryInfo
                {
                    Address = localUrl,
                    Id = _appHost.SystemId,
                    Name = _appHost.FriendlyName
                };

                await SendAsync(encoding.GetBytes(_json.SerializeToString(response)), endpoint);
            }
            else
            {
                _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
            }
        }
示例#4
0
        private async void RespondToV2Message(string endpoint)
        {
            var info = _appHost.GetSystemInfo();

            if (!string.IsNullOrEmpty(info.LocalAddress))
            {
                var response = new ServerDiscoveryInfo
                {
                    Address = info.LocalAddress,
                    Id = info.Id,
                    Name = info.ServerName
                };

                await SendAsync(Encoding.UTF8.GetBytes(_json.SerializeToString(response)), endpoint);
            }
            else
            {
                _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
            }
        }
        private string ConvertEndpointAddressToManualAddress(ServerDiscoveryInfo info)
        {
            if (!string.IsNullOrWhiteSpace(info.Address) && !string.IsNullOrWhiteSpace(info.EndpointAddress))
            {
                var address = info.EndpointAddress.Split(':').First();

                // Determine the port, if any
                var parts = info.Address.Split(':');
                if (parts.Length > 1)
                {
                    var portString = parts.Last();
                    int port;
                    if (int.TryParse(portString, NumberStyles.Any, CultureInfo.InvariantCulture, out port))
                    {
                        address += ":" + portString;
                    }
                }

                return NormalizeAddress(address);
            }

            return null;
        }