jellyfin/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs

99 lines
3.2 KiB
C#
Raw Normal View History

2013-05-19 00:07:59 +02:00
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
2013-12-07 16:52:38 +01:00
using MediaBrowser.Controller.Net;
2013-05-19 00:07:59 +02:00
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Implementations.Udp;
using System.Net.Sockets;
2013-09-25 02:54:51 +02:00
namespace MediaBrowser.Server.Implementations.EntryPoints
2013-05-19 00:07:59 +02:00
{
/// <summary>
/// Class UdpServerEntryPoint
/// </summary>
2013-05-19 00:07:59 +02:00
public class UdpServerEntryPoint : IServerEntryPoint
{
/// <summary>
/// Gets or sets the UDP server.
/// </summary>
/// <value>The UDP server.</value>
private UdpServer UdpServer { get; set; }
/// <summary>
/// The _logger
/// </summary>
2013-05-19 00:07:59 +02:00
private readonly ILogger _logger;
/// <summary>
/// The _network manager
/// </summary>
2013-05-19 00:07:59 +02:00
private readonly INetworkManager _networkManager;
/// <summary>
/// The _server configuration manager
/// </summary>
2013-05-19 00:07:59 +02:00
private readonly IServerConfigurationManager _serverConfigurationManager;
/// <summary>
/// The _HTTP server
/// </summary>
private readonly IHttpServer _httpServer;
2013-05-19 00:07:59 +02:00
2013-09-25 02:54:51 +02:00
public const int PortNumber = 7359;
/// <summary>
/// Initializes a new instance of the <see cref="UdpServerEntryPoint"/> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="networkManager">The network manager.</param>
/// <param name="serverConfigurationManager">The server configuration manager.</param>
/// <param name="httpServer">The HTTP server.</param>
public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer)
2013-05-19 00:07:59 +02:00
{
_logger = logger;
_networkManager = networkManager;
_serverConfigurationManager = serverConfigurationManager;
_httpServer = httpServer;
2013-05-19 00:07:59 +02:00
}
/// <summary>
/// Runs this instance.
/// </summary>
2013-05-19 00:07:59 +02:00
public void Run()
{
var udpServer = new UdpServer(_logger, _networkManager, _serverConfigurationManager, _httpServer);
2013-05-19 00:07:59 +02:00
try
{
2013-09-25 02:54:51 +02:00
udpServer.Start(PortNumber);
2013-05-19 00:07:59 +02:00
UdpServer = udpServer;
}
catch (SocketException ex)
{
_logger.ErrorException("Failed to start UDP Server", ex);
}
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
2013-05-19 00:07:59 +02:00
public void Dispose()
{
Dispose(true);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
2013-05-19 00:07:59 +02:00
protected virtual void Dispose(bool dispose)
{
if (dispose)
{
if (UdpServer != null)
{
UdpServer.Dispose();
}
}
}
}
}