예제 #1
0
        /// <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
        /// <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
        /// <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
        /// <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
        /// <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
        /// <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);
                }
            }
        }