2016-11-04 07:09:21 -07:00
|
|
|
|
using System;
|
2014-07-27 15:01:29 -07:00
|
|
|
|
using MediaBrowser.Controller;
|
2013-05-18 15:07:59 -07:00
|
|
|
|
using MediaBrowser.Controller.Plugins;
|
|
|
|
|
using MediaBrowser.Model.Logging;
|
2014-07-29 20:31:35 -07:00
|
|
|
|
using MediaBrowser.Model.Serialization;
|
2016-11-04 11:56:47 -07:00
|
|
|
|
using Emby.Server.Implementations.Udp;
|
|
|
|
|
using MediaBrowser.Model.Net;
|
2013-05-18 15:07:59 -07:00
|
|
|
|
|
2016-11-04 11:56:47 -07:00
|
|
|
|
namespace Emby.Server.Implementations.EntryPoints
|
2013-05-18 15:07:59 -07:00
|
|
|
|
{
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class UdpServerEntryPoint
|
|
|
|
|
/// </summary>
|
2013-05-18 15:07:59 -07:00
|
|
|
|
public class UdpServerEntryPoint : IServerEntryPoint
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets the UDP server.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value>The UDP server.</value>
|
|
|
|
|
private UdpServer UdpServer { get; set; }
|
|
|
|
|
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The _logger
|
|
|
|
|
/// </summary>
|
2013-05-18 15:07:59 -07:00
|
|
|
|
private readonly ILogger _logger;
|
2016-11-04 11:56:47 -07:00
|
|
|
|
private readonly ISocketFactory _socketFactory;
|
2014-07-27 15:01:29 -07:00
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
2014-07-29 20:31:35 -07:00
|
|
|
|
private readonly IJsonSerializer _json;
|
2013-05-18 15:07:59 -07:00
|
|
|
|
|
2013-09-24 17:54:51 -07:00
|
|
|
|
public const int PortNumber = 7359;
|
|
|
|
|
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// <summary>
|
2014-08-19 15:28:35 -07:00
|
|
|
|
/// Initializes a new instance of the <see cref="UdpServerEntryPoint" /> class.
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// </summary>
|
2016-11-04 11:56:47 -07:00
|
|
|
|
public UdpServerEntryPoint(ILogger logger, IServerApplicationHost appHost, IJsonSerializer json, ISocketFactory socketFactory)
|
2013-05-18 15:07:59 -07:00
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
2014-07-27 15:01:29 -07:00
|
|
|
|
_appHost = appHost;
|
2014-07-29 20:31:35 -07:00
|
|
|
|
_json = json;
|
2016-11-04 11:56:47 -07:00
|
|
|
|
_socketFactory = socketFactory;
|
2013-05-18 15:07:59 -07:00
|
|
|
|
}
|
2013-05-27 11:34:03 -07:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs this instance.
|
|
|
|
|
/// </summary>
|
2013-05-18 15:07:59 -07:00
|
|
|
|
public void Run()
|
|
|
|
|
{
|
2016-11-04 11:56:47 -07:00
|
|
|
|
var udpServer = new UdpServer(_logger, _appHost, _json, _socketFactory);
|
2013-05-18 15:07:59 -07:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2013-09-24 17:54:51 -07:00
|
|
|
|
udpServer.Start(PortNumber);
|
2013-05-18 15:07:59 -07:00
|
|
|
|
|
|
|
|
|
UdpServer = udpServer;
|
|
|
|
|
}
|
2016-11-04 07:09:21 -07:00
|
|
|
|
catch (Exception ex)
|
2013-05-18 15:07:59 -07:00
|
|
|
|
{
|
|
|
|
|
_logger.ErrorException("Failed to start UDP Server", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
|
|
|
|
/// </summary>
|
2013-05-18 15:07:59 -07:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-27 11:34:03 -07:00
|
|
|
|
/// <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 15:07:59 -07:00
|
|
|
|
protected virtual void Dispose(bool dispose)
|
|
|
|
|
{
|
|
|
|
|
if (dispose)
|
|
|
|
|
{
|
|
|
|
|
if (UdpServer != null)
|
|
|
|
|
{
|
|
|
|
|
UdpServer.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|