public abstract CloseOutputAsync ( System closeStatus, string statusDescription, System cancellationToken ) : System.Threading.Tasks.Task | ||
closeStatus | System | |
statusDescription | string | |
cancellationToken | System | |
return | System.Threading.Tasks.Task |
public override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) { ThrowIfNotConnected(); WebSocketValidate.ValidateCloseStatus(closeStatus, statusDescription); return(_innerWebSocket.CloseOutputAsync(closeStatus, statusDescription, cancellationToken)); }
protected override async void OnClose(CancellationToken ct) { try { await _webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Session Ended", ct); } catch { } try { await _webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Session Ended", ct); } catch { } }
public static void RemoveUserInfoAndWebSocket(string token) { System.Net.WebSockets.WebSocket webSocket = WebSocketsDict[token]; UserInfo userInfo = UserInfoDict[token]; UserNameMappingUserInfoDict.TryRemove(userInfo.UserName, out UserInfo info); WebSocketsDict.TryRemove(token, out System.Net.WebSockets.WebSocket socket); UserInfoDict.TryRemove(token, out UserInfo info2); try { webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "AutoLogout", CancellationToken.None); } catch (Exception ex) { } }
public virtual Task CloseAsync() { if (_webSocket.State == WebSocketState.Closed || _webSocket.State == WebSocketState.Aborted || _webSocket.State == WebSocketState.CloseSent) { return(Task.CompletedTask); } try { _disconnectToken.ThrowIfCancellationRequested(); return(_webSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None)); } catch (Exception ex) { Trace.TraceError("Error Closing : " + ex.Message); } return(Task.CompletedTask); }
/// <summary> /// Closes the transport, implementing the websocket close handshake. /// </summary> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="InvalidOperationException">The listener is not active</exception> protected override async Task PerformCloseAsync(CancellationToken cancellationToken) { await _closeSemaphore.WaitAsync(cancellationToken); try { await _envelopePipe.StopAsync(cancellationToken); // Awaits for the client to send the close connection frame. // If the session was clearly closed, the client should received the finished envelope and is closing the connection. using (var cts = new CancellationTokenSource(CloseTimeout)) using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, cts.Token)) { if (WebSocket.State == WebSocketState.Open || WebSocket.State == WebSocketState.CloseReceived) { if (_closeGracefully) { await WebSocket.CloseAsync(_closeStatus, _closeStatusDescription, linkedCts.Token) .ConfigureAwait(false); } else { await WebSocket.CloseOutputAsync(_closeStatus, _closeStatusDescription, linkedCts.Token) .ConfigureAwait(false); } } } } finally { _closeSemaphore.Release(); } }
private static WebSocketCloseAsync WebSocketCloseAsync(WebSocket webSocket) { return (status, description, cancel) => webSocket.CloseOutputAsync((WebSocketCloseStatus)status, description, cancel); }
public override async Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken) { await _webSocket.CloseOutputAsync(closeStatus, statusDescription, cancellationToken); }