예제 #1
0
            public override async Task PingAsync()
            {
                if (this._connection.IsClosed)
                {
                    return;
                }

                if (this._lastPong.Elapsed > this._pingTimeout)
                {
                    await this._connection.CloseAsync(WebSocketCloseReasons.GoingAway).ConfigureAwait(false);

                    return;
                }

                var messageType = (WebSocketMessageType)WebSocketFrameOption.Ping;
                var count       = this._pingBuffer.Array[this._pingBuffer.Offset];
                var payload     = this._pingBuffer.Skip(1);

                var pingFrame = _connection.PrepareFrame(payload, count, true, false, messageType, WebSocketExtensionFlags.None);

                if (await _connection.SendFrameAsync(pingFrame, TimeSpan.Zero, SendOptions.NoErrors, CancellationToken.None).ConfigureAwait(false))
                {
                    this._lastPong.Restart();
                }
            }
예제 #2
0
            public override async Task PingAsync()
            {
                if (this._connection.IsClosed)
                {
                    return;
                }

                if (this._lastPong.Elapsed > this._pingTimeout)
                {
                    await this._connection.CloseAsync(WebSocketCloseReasons.GoingAway).ConfigureAwait(false);

                    return;
                }

                ((ulong)Stopwatch.GetTimestamp()).ToBytes(_pingBuffer.Array, _pingBuffer.Offset);
                var messageType = (WebSocketMessageType)WebSocketFrameOption.Ping;

                var pingFrame = _connection.PrepareFrame(_pingBuffer, 8, true, false, messageType, WebSocketExtensionFlags.None);

                if (await _connection.SendFrameAsync(pingFrame, TimeSpan.Zero, SendOptions.NoErrors, CancellationToken.None).ConfigureAwait(false))
                {
                    this._lastPong.Restart();
                }
            }