コード例 #1
0
        public async Task <bool> TryPingAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            await SendAsync(PingPayload.Create(), ioBehavior, cancellationToken).ConfigureAwait(false);

            try
            {
                var payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

                OkPayload.Create(payload);
                return(true);
            }
            catch (EndOfStreamException)
            {
            }
            catch (SocketException)
            {
            }

            return(false);
        }
コード例 #2
0
        public async Task <bool> TryPingAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
        {
            VerifyState(State.Connected);

            // send ping payload to verify client and server socket are still connected
            try
            {
                await SendAsync(PingPayload.Create(), ioBehavior, cancellationToken).ConfigureAwait(false);

                var payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);

                OkPayload.Create(payload);
                return(true);
            }
            catch (IOException)
            {
            }
            catch (SocketException)
            {
            }

            VerifyState(State.Failed);
            return(false);
        }