UdpServerEntryPoint.cs 3.2 KB

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