コード例 #1
0
ファイル: UdpServer.cs プロジェクト: jrags56/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var responder = _responders.FirstOrDefault(i => i.Item2.SequenceEqual(e.Bytes));
            var encoding  = Encoding.UTF8;

            if (responder == null)
            {
                var text = Encoding.Unicode.GetString(e.Bytes);
                responder = _responders.FirstOrDefault(i => string.Equals(i.Item1, text, StringComparison.OrdinalIgnoreCase));

                if (responder != null)
                {
                    encoding = Encoding.Unicode;
                }
            }

            if (responder != null)
            {
                try
                {
                    responder.Item3(e.RemoteEndPoint, encoding);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }
コード例 #2
0
ファイル: UdpServer.cs プロジェクト: yardameus/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            const string context = "Server";

            var expectedMessage      = String.Format("who is MediaBrowser{0}?", context);
            var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage);

            if (expectedMessageBytes.SequenceEqual(e.Bytes))
            {
                _logger.Info("Received UDP server request from " + e.RemoteEndPoint);

                var localAddress = GetLocalIpAddress();

                if (!string.IsNullOrEmpty(localAddress))
                {
                    // Send a response back with our ip address and port
                    var response = String.Format("MediaBrowser{0}|{1}:{2}", context, GetLocalIpAddress(), _serverConfigurationManager.Configuration.HttpServerPortNumber);

                    await SendAsync(Encoding.UTF8.GetBytes(response), e.RemoteEndPoint);
                }
                else
                {
                    _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
                }
            }
        }
コード例 #3
0
ファイル: UdpServer.cs プロジェクト: snap608/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            const string context = "Server";

            var expectedMessage = String.Format("who is MediaBrowser{0}?", context);
            var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage);

            if (expectedMessageBytes.SequenceEqual(e.Bytes))
            {
                _logger.Info("Received UDP server request from " + e.RemoteEndPoint);

                var localAddress = GetLocalIpAddress();

                if (!string.IsNullOrEmpty(localAddress))
                {
                    // Send a response back with our ip address and port
                    var response = String.Format("MediaBrowser{0}|{1}:{2}", context, GetLocalIpAddress(), _serverConfigurationManager.Configuration.HttpServerPortNumber);

                    await SendAsync(Encoding.UTF8.GetBytes(response), e.RemoteEndPoint);
                }
                else
                {
                    _logger.Warn("Unable to respond to udp request because the local ip address could not be determined.");
                }
            }
        }
コード例 #4
0
ファイル: UdpServer.cs プロジェクト: softworkz/Emby
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var responder = _responders.FirstOrDefault(i => i.Item2.SequenceEqual(e.Bytes));
            var encoding = Encoding.UTF8;

            if (responder == null)
            {
                var text = Encoding.Unicode.GetString(e.Bytes);
                responder = _responders.FirstOrDefault(i => string.Equals(i.Item1, text, StringComparison.OrdinalIgnoreCase));

                if (responder != null)
                {
                    encoding = Encoding.Unicode;
                }
            }

            if (responder != null)
            {
                try
                {
                    responder.Item3(e.RemoteEndPoint, encoding);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }
コード例 #5
0
ファイル: UdpServer.cs プロジェクト: rsolmn/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var responder = _responders.FirstOrDefault(i => i.Item1.SequenceEqual(e.Bytes));

            if (responder != null)
            {
                try
                {
                    responder.Item2(e.RemoteEndPoint);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }
コード例 #6
0
ファイル: UdpServer.cs プロジェクト: willyelm/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var responder = _responders.FirstOrDefault(i => i.Item1.SequenceEqual(e.Bytes));

            if (responder != null)
            {
                try
                {
                    responder.Item2(e.RemoteEndPoint);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }
コード例 #7
0
ファイル: UdpServer.cs プロジェクト: rajeshwarn/MediaBrowser
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs" /> instance containing the event data.</param>
        private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var context = "Server";

            var expectedMessage      = String.Format("who is MediaBrowser{0}?", context);
            var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage);

            if (expectedMessageBytes.SequenceEqual(e.Bytes))
            {
                _logger.Info("Received UDP server request from " + e.RemoteEndPoint);

                // Send a response back with our ip address and port
                var response = String.Format("MediaBrowser{0}|{1}:{2}", context, _networkManager.GetLocalIpAddress(), _serverConfigurationManager.Configuration.HttpServerPortNumber);

                await SendAsync(Encoding.UTF8.GetBytes(response), e.RemoteEndPoint);
            }
        }
コード例 #8
0
ファイル: UdpServer.cs プロジェクト: t-andre/Emby
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var encoding = Encoding.UTF8;
            var responder = GetResponder(e.Bytes, encoding);

            if (responder == null)
            {
                encoding = Encoding.Unicode;
                responder = GetResponder(e.Bytes, encoding);
            }

            if (responder != null)
            {
                try
                {
                    await responder.Item2.Item3(responder.Item1, e.RemoteEndPoint, encoding).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Raises the <see cref="E:MessageReceived" /> event.
        /// </summary>
        /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param>
        private async void OnMessageReceived(UdpMessageReceivedEventArgs e)
        {
            var encoding  = Encoding.UTF8;
            var responder = GetResponder(e.Bytes, encoding);

            if (responder == null)
            {
                encoding  = Encoding.Unicode;
                responder = GetResponder(e.Bytes, encoding);
            }

            if (responder != null)
            {
                try
                {
                    await responder.Item2.Item3(responder.Item1, e.RemoteEndPoint, encoding).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error in OnMessageReceived", ex);
                }
            }
        }