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

93 lines
2.9 KiB
C#
Raw Normal View History

2013-05-18 22:07:59 +00:00
using MediaBrowser.Common.Net;
2014-07-27 22:01:29 +00:00
using MediaBrowser.Controller;
2013-05-18 22:07:59 +00:00
using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.Logging;
2014-07-30 03:31:35 +00:00
using MediaBrowser.Model.Serialization;
2013-05-18 22:07:59 +00:00
using MediaBrowser.Server.Implementations.Udp;
using System.Net.Sockets;
2013-09-25 00:54:51 +00:00
namespace MediaBrowser.Server.Implementations.EntryPoints
2013-05-18 22:07:59 +00:00
{
/// <summary>
/// Class UdpServerEntryPoint
/// </summary>
2013-05-18 22:07:59 +00: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-18 22:07:59 +00:00
private readonly ILogger _logger;
/// <summary>
/// The _network manager
/// </summary>
2013-05-18 22:07:59 +00:00
private readonly INetworkManager _networkManager;
2014-07-27 22:01:29 +00:00
private readonly IServerApplicationHost _appHost;
2014-07-30 03:31:35 +00:00
private readonly IJsonSerializer _json;
2013-05-18 22:07:59 +00:00
2013-09-25 00:54:51 +00:00
public const int PortNumber = 7359;
/// <summary>
2014-08-19 22:28:35 +00:00
/// Initializes a new instance of the <see cref="UdpServerEntryPoint" /> class.
/// </summary>
/// <param name="logger">The logger.</param>
/// <param name="networkManager">The network manager.</param>
2014-08-19 22:28:35 +00:00
/// <param name="appHost">The application host.</param>
/// <param name="json">The json.</param>
public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerApplicationHost appHost, IJsonSerializer json)
2013-05-18 22:07:59 +00:00
{
_logger = logger;
_networkManager = networkManager;
2014-07-27 22:01:29 +00:00
_appHost = appHost;
2014-07-30 03:31:35 +00:00
_json = json;
2013-05-18 22:07:59 +00:00
}
/// <summary>
/// Runs this instance.
/// </summary>
2013-05-18 22:07:59 +00:00
public void Run()
{
2014-08-19 22:28:35 +00:00
var udpServer = new UdpServer(_logger, _networkManager, _appHost, _json);
2013-05-18 22:07:59 +00:00
try
{
2013-09-25 00:54:51 +00:00
udpServer.Start(PortNumber);
2013-05-18 22:07:59 +00: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-18 22:07:59 +00: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-18 22:07:59 +00:00
protected virtual void Dispose(bool dispose)
{
if (dispose)
{
if (UdpServer != null)
{
UdpServer.Dispose();
}
}
}
}
}