UdpServerEntryPoint.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using MediaBrowser.Common.Net;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Plugins;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Server.Implementations.Udp;
  6. using System.Net.Sockets;
  7. namespace MediaBrowser.Server.Implementations.EntryPoints
  8. {
  9. /// <summary>
  10. /// Class UdpServerEntryPoint
  11. /// </summary>
  12. public class UdpServerEntryPoint : IServerEntryPoint
  13. {
  14. /// <summary>
  15. /// Gets or sets the UDP server.
  16. /// </summary>
  17. /// <value>The UDP server.</value>
  18. private UdpServer UdpServer { get; set; }
  19. /// <summary>
  20. /// The _logger
  21. /// </summary>
  22. private readonly ILogger _logger;
  23. /// <summary>
  24. /// The _network manager
  25. /// </summary>
  26. private readonly INetworkManager _networkManager;
  27. /// <summary>
  28. /// The _server configuration manager
  29. /// </summary>
  30. private readonly IServerConfigurationManager _serverConfigurationManager;
  31. /// <summary>
  32. /// The _HTTP server
  33. /// </summary>
  34. private readonly IHttpServer _httpServer;
  35. public const int PortNumber = 7359;
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="UdpServerEntryPoint"/> class.
  38. /// </summary>
  39. /// <param name="logger">The logger.</param>
  40. /// <param name="networkManager">The network manager.</param>
  41. /// <param name="serverConfigurationManager">The server configuration manager.</param>
  42. /// <param name="httpServer">The HTTP server.</param>
  43. public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer)
  44. {
  45. _logger = logger;
  46. _networkManager = networkManager;
  47. _serverConfigurationManager = serverConfigurationManager;
  48. _httpServer = httpServer;
  49. }
  50. /// <summary>
  51. /// Runs this instance.
  52. /// </summary>
  53. public void Run()
  54. {
  55. var udpServer = new UdpServer(_logger, _networkManager, _serverConfigurationManager, _httpServer);
  56. try
  57. {
  58. udpServer.Start(PortNumber);
  59. UdpServer = udpServer;
  60. }
  61. catch (SocketException ex)
  62. {
  63. _logger.ErrorException("Failed to start UDP Server", ex);
  64. }
  65. }
  66. /// <summary>
  67. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  68. /// </summary>
  69. public void Dispose()
  70. {
  71. Dispose(true);
  72. }
  73. /// <summary>
  74. /// Releases unmanaged and - optionally - managed resources.
  75. /// </summary>
  76. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  77. protected virtual void Dispose(bool dispose)
  78. {
  79. if (dispose)
  80. {
  81. if (UdpServer != null)
  82. {
  83. UdpServer.Dispose();
  84. }
  85. }
  86. }
  87. }
  88. }