UdpServerEntryPoint.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using MediaBrowser.Controller;
  3. using MediaBrowser.Controller.Plugins;
  4. using MediaBrowser.Model.Logging;
  5. using MediaBrowser.Model.Serialization;
  6. using Emby.Server.Implementations.Udp;
  7. using MediaBrowser.Model.Net;
  8. namespace Emby.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. private readonly ISocketFactory _socketFactory;
  25. private readonly IServerApplicationHost _appHost;
  26. private readonly IJsonSerializer _json;
  27. public const int PortNumber = 7359;
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="UdpServerEntryPoint" /> class.
  30. /// </summary>
  31. public UdpServerEntryPoint(ILogger logger, IServerApplicationHost appHost, IJsonSerializer json, ISocketFactory socketFactory)
  32. {
  33. _logger = logger;
  34. _appHost = appHost;
  35. _json = json;
  36. _socketFactory = socketFactory;
  37. }
  38. /// <summary>
  39. /// Runs this instance.
  40. /// </summary>
  41. public void Run()
  42. {
  43. // ToDo: Fix This
  44. return;
  45. var udpServer = new UdpServer(_logger, _appHost, _json, _socketFactory);
  46. try
  47. {
  48. udpServer.Start(PortNumber);
  49. UdpServer = udpServer;
  50. }
  51. catch (Exception ex)
  52. {
  53. _logger.ErrorException("Failed to start UDP Server", ex);
  54. }
  55. }
  56. /// <summary>
  57. /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  58. /// </summary>
  59. public void Dispose()
  60. {
  61. Dispose(true);
  62. }
  63. /// <summary>
  64. /// Releases unmanaged and - optionally - managed resources.
  65. /// </summary>
  66. /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  67. protected virtual void Dispose(bool dispose)
  68. {
  69. if (dispose)
  70. {
  71. if (UdpServer != null)
  72. {
  73. UdpServer.Dispose();
  74. }
  75. }
  76. }
  77. }
  78. }