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