INetworkTransport.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Net;
  3. namespace Microsoft.Xna.Framework.Net
  4. {
  5. /// <summary>
  6. /// Defines the contract for a network transport layer, providing methods for sending and receiving data.
  7. /// </summary>
  8. public interface INetworkTransport : IDisposable
  9. {
  10. /// <summary>
  11. /// Receives data from the network in a blocking manner.
  12. /// </summary>
  13. /// <returns>A tuple containing the received data and the sender's endpoint.</returns>
  14. (byte[] data, IPEndPoint sender) Receive();
  15. /// <summary>
  16. /// Receives data from the network asynchronously.
  17. /// </summary>
  18. /// <returns>A task that represents the asynchronous operation. The result contains the received data and the sender's endpoint.</returns>
  19. Task<(byte[] data, IPEndPoint sender)> ReceiveAsync();
  20. /// <summary>
  21. /// Sends data to the specified endpoint in a blocking manner.
  22. /// </summary>
  23. /// <param name="data">The data to send.</param>
  24. /// <param name="endpoint">The endpoint to send the data to.</param>
  25. void Send(byte[] data, IPEndPoint endpoint);
  26. /// <summary>
  27. /// Sends data to the specified endpoint asynchronously.
  28. /// </summary>
  29. /// <param name="data">The data to send.</param>
  30. /// <param name="endpoint">The endpoint to send the data to.</param>
  31. /// <returns>A task that represents the asynchronous operation.</returns>
  32. Task SendAsync(byte[] data, IPEndPoint endpoint);
  33. /// <summary>
  34. /// Binds the transport to a local endpoint for receiving data.
  35. /// </summary>
  36. void Bind();
  37. /// <summary>
  38. /// Indicates whether the transport is currently bound to a local endpoint.
  39. /// </summary>
  40. bool IsBound { get; }
  41. }
  42. }