ISsdpCommunicationsServer.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Threading.Tasks;
  3. namespace Rssdp.Infrastructure
  4. {
  5. /// <summary>
  6. /// Interface for a component that manages network communication (sending and receiving HTTPU messages) for the SSDP protocol.
  7. /// </summary>
  8. public interface ISsdpCommunicationsServer : IDisposable
  9. {
  10. #region Events
  11. /// <summary>
  12. /// Raised when a HTTPU request message is received by a socket (unicast or multicast).
  13. /// </summary>
  14. event EventHandler<RequestReceivedEventArgs> RequestReceived;
  15. /// <summary>
  16. /// Raised when an HTTPU response message is received by a socket (unicast or multicast).
  17. /// </summary>
  18. event EventHandler<ResponseReceivedEventArgs> ResponseReceived;
  19. #endregion
  20. #region Methods
  21. /// <summary>
  22. /// Causes the server to begin listening for multicast messages, being SSDP search requests and notifications.
  23. /// </summary>
  24. void BeginListeningForBroadcasts();
  25. /// <summary>
  26. /// Causes the server to stop listening for multicast messages, being SSDP search requests and notifications.
  27. /// </summary>
  28. void StopListeningForBroadcasts();
  29. /// <summary>
  30. /// Stops listening for search responses on the local, unicast socket.
  31. /// </summary>
  32. void StopListeningForResponses();
  33. /// <summary>
  34. /// Sends a message to a particular address (uni or multicast) and port.
  35. /// </summary>
  36. /// <param name="messageData">A byte array containing the data to send.</param>
  37. /// <param name="destination">A <see cref="UdpEndPoint"/> representing the destination address for the data. Can be either a multicast or unicast destination.</param>
  38. Task SendMessage(byte[] messageData, UdpEndPoint destination);
  39. /// <summary>
  40. /// Sends a message to the SSDP multicast address and port.
  41. /// </summary>
  42. /// <param name="messageData">A byte array containing the data to send.</param>
  43. Task SendMulticastMessage(byte[] messageData);
  44. #endregion
  45. #region Properties
  46. /// <summary>
  47. /// Gets or sets a boolean value indicating whether or not this instance is shared amongst multiple <see cref="SsdpDeviceLocatorBase"/> and/or <see cref="ISsdpDevicePublisher"/> instances.
  48. /// </summary>
  49. /// <remarks>
  50. /// <para>If true, disposing an instance of a <see cref="SsdpDeviceLocatorBase"/>or a <see cref="ISsdpDevicePublisher"/> will not dispose this comms server instance. The calling code is responsible for managing the lifetime of the server.</para>
  51. /// </remarks>
  52. bool IsShared { get; set; }
  53. #endregion
  54. }
  55. }