UdpServerEntryPoint.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.ServerApplication.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. /// <summary>
  36. /// Initializes a new instance of the <see cref="UdpServerEntryPoint"/> class.
  37. /// </summary>
  38. /// <param name="logger">The logger.</param>
  39. /// <param name="networkManager">The network manager.</param>
  40. /// <param name="serverConfigurationManager">The server configuration manager.</param>
  41. /// <param name="httpServer">The HTTP server.</param>
  42. public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer)
  43. {
  44. _logger = logger;
  45. _networkManager = networkManager;
  46. _serverConfigurationManager = serverConfigurationManager;
  47. _httpServer = httpServer;
  48. }
  49. /// <summary>
  50. /// Runs this instance.
  51. /// </summary>
  52. public void Run()
  53. {
  54. var udpServer = new UdpServer(_logger, _networkManager, _serverConfigurationManager, _httpServer);
  55. try
  56. {
  57. udpServer.Start(ApplicationHost.UdpServerPort);
  58. UdpServer = udpServer;
  59. }
  60. catch (SocketException ex)
  61. {
  62. _logger.ErrorException("Failed to start UDP Server", ex);
  63. }
  64. }
  65. /// <summary>
  66. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  67. /// </summary>
  68. public void Dispose()
  69. {
  70. Dispose(true);
  71. }
  72. /// <summary>
  73. /// Releases unmanaged and - optionally - managed resources.
  74. /// </summary>
  75. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  76. protected virtual void Dispose(bool dispose)
  77. {
  78. if (dispose)
  79. {
  80. if (UdpServer != null)
  81. {
  82. UdpServer.Dispose();
  83. }
  84. }
  85. }
  86. }
  87. }