ITransport.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #if !BESTHTTP_DISABLE_SOCKETIO
  2. using System.Collections.Generic;
  3. namespace BestHTTP.SocketIO.Transports
  4. {
  5. public enum TransportTypes
  6. {
  7. Polling,
  8. #if !BESTHTTP_DISABLE_WEBSOCKET
  9. WebSocket
  10. #endif
  11. }
  12. /// <summary>
  13. /// Possible states of an ITransport implementation.
  14. /// </summary>
  15. public enum TransportStates : int
  16. {
  17. /// <summary>
  18. /// The transport is connecting to the server.
  19. /// </summary>
  20. Connecting = 0,
  21. /// <summary>
  22. /// The transport is connected, and started the opening process.
  23. /// </summary>
  24. Opening = 1,
  25. /// <summary>
  26. /// The transport is open, can send and receive packets.
  27. /// </summary>
  28. Open = 2,
  29. /// <summary>
  30. /// The transport is closed.
  31. /// </summary>
  32. Closed = 3,
  33. /// <summary>
  34. /// The transport is paused.
  35. /// </summary>
  36. Paused = 4
  37. }
  38. /// <summary>
  39. /// An interface that a Socket.IO transport must implement.
  40. /// </summary>
  41. public interface ITransport
  42. {
  43. /// <summary>
  44. /// Type of this transport.
  45. /// </summary>
  46. TransportTypes Type { get; }
  47. /// <summary>
  48. /// Current state of the transport
  49. /// </summary>
  50. TransportStates State { get; }
  51. /// <summary>
  52. /// SocketManager instance that this transport is bound to.
  53. /// </summary>
  54. SocketManager Manager { get; }
  55. /// <summary>
  56. /// True if the transport is busy with sending messages.
  57. /// </summary>
  58. bool IsRequestInProgress { get; }
  59. /// <summary>
  60. /// True if the transport is busy with a poll request.
  61. /// </summary>
  62. bool IsPollingInProgress { get; }
  63. /// <summary>
  64. /// Start open/upgrade the transport.
  65. /// </summary>
  66. void Open();
  67. /// <summary>
  68. /// Do a poll for available messages on the server.
  69. /// </summary>
  70. void Poll();
  71. /// <summary>
  72. /// Send a single packet to the server.
  73. /// </summary>
  74. void Send(Packet packet);
  75. /// <summary>
  76. /// Send a list of packets to the server.
  77. /// </summary>
  78. void Send(List<Packet> packets);
  79. /// <summary>
  80. /// Close this transport.
  81. /// </summary>
  82. void Close();
  83. }
  84. }
  85. #endif