コード例 #1
0
        public async Task CloseConnection(WebSocketCloseStatus status = WebSocketCloseStatus.NormalClosure, string desc = null)
        {
            try
            {
                Global.ExtensionsManager.BeforeConnectionClose(this);
                if (webSocket.State == WebSocketState.Open)
                {
                    var connectionPubKey = "no public key";
                    if (ClientPubKey != null)
                    {
                        connectionPubKey = $"public key {ClientPubKey}";
                    }
                    desc = desc ?? status.ToString();
                    logger.Trace($"Connection with {connectionPubKey} is closed. Status: {status}, description: {desc}");

                    await sendMessageSemaphore.WaitAsync();

                    try
                    {
                        var timeoutTokenSource = new CancellationTokenSource(1000);
                        await webSocket.CloseAsync(status, desc, timeoutTokenSource.Token);

                        cancellationTokenSource?.Cancel();
                    }
                    catch (WebSocketException exc)
                    {
                        //ignore client disconnection
                        if (exc.WebSocketErrorCode != WebSocketError.ConnectionClosedPrematurely &&
                            exc.WebSocketErrorCode != WebSocketError.InvalidState)
                        {
                            throw;
                        }
                    }
                    catch (OperationCanceledException) { }
                    finally
                    {
                        sendMessageSemaphore?.Release();
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error(e, "Error on close connection");
            }
        }
コード例 #2
0
        public async Task CloseAsync(WebSocketCloseStatus closeState = WebSocketCloseStatus.NormalClosure)
        {
            OnDebug("Closing");
            OnClosing();

            var closeMessage = closeState == WebSocketCloseStatus.NormalClosure
                ? null
                : closeState.ToString();

            await Socket
            .CloseAsync(closeState, closeMessage, CancellationToken.None)
            .ConfigureAwait(false);

            while (State == WebSocketState.Open ||
                   State == WebSocketState.CloseSent)
            {
                await Task.Yield();
            }
        }
コード例 #3
0
 private void ChatClient_DisconnectOccurred(object sender, WebSocketCloseStatus e)
 {
     Assert.Fail("Disconnection occurred: " + e.ToString());
 }
コード例 #4
0
 public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
 {
     logger.Info("ContainerProcessHandler.OnClose", new Dictionary<string, object> {{"closeStatus", closeStatus.ToString()}, {"closeStatusDescription", closeStatusDescription}});
 }
コード例 #5
0
 public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
 {
     logger.Info("OnClose: {0} :: {1}", closeStatus.ToString(), closeStatusDescription);
 }
コード例 #6
0
 private void WSOnClosed(WebSocketCloseStatus reason)
 {
     logger.LogInformation($"OnClosed - Connection Closed: {reason.ToString()}");
 }
コード例 #7
0
 /// <summary>
 /// Stopping connection to a websocket
 /// </summary>
 public async Task StopAsync(WebSocketCloseStatus status, string statusDescription)
 {
     //TODO Finish implementation of the stop method for the socketclient
     this._logger?.Debug($"Connection will be closed with this status {status.ToString()} and the following description: {statusDescription}");
     await this._webSocket.CloseAsync(status, statusDescription, this._cancellationTokenSource.Token);
 }
コード例 #8
0
ファイル: SocketHandle.cs プロジェクト: sirhypernova/DNet
 private void WS_OnClosed(WebSocketCloseStatus reason)
 {
     Console.WriteLine($"WS Socket closed => {reason.ToString()}");
 }