/// <summary>
 /// Initialises a new instance of the PingPongManager to facilitate ping pong WebSocket messages.
 /// </summary>
 /// <param name="websocket">The WebSocket instance used to listen to ping messages and send pong messages</param>
 /// <param name="cancellationToken">The token used to cancel a pending ping send AND the automatic sending of ping messages if KeepAliveInterval is positive</param>
 public PingPongManager(WebSocketImplementation websocket, CancellationToken cancellationToken)
 {
     this._websocket         = websocket;
     this._websocket.Pong   += this.DoPong;
     this._cancellationToken = cancellationToken;
     this._stopwatch         = Stopwatch.StartNew();
     this._pingTask          = Task.Run(this.DoPingAsync);
 }
예제 #2
0
 public PingPongManager(WebSocketImplementation websocket, WebSocketOptions options, CancellationToken cancellationToken)
 {
     this._websocket         = websocket;
     this._cancellationToken = cancellationToken;
     this._getPongPayload    = options.GetPongPayload;
     this._onPong            = options.OnPong;
     if (this._websocket.KeepAliveInterval != TimeSpan.Zero)
     {
         this._getPingPayload = options.GetPingPayload;
         Task.Run(this.SendPingAsync).ConfigureAwait(false);
     }
 }