public override void OnClose() { clientsWS.Remove(this); string key = GetClientKey(this); LogDebug($"Client websocket disconnected '{key}'"); ExecuteHandler(HandlerType.OnClose, new Object[] { key }); OnSessionClosed?.Invoke(key, string.Empty); base.OnClose(); }
public override void OnError() { base.OnError(); string key = GetClientKey(this); if (!ExecuteHandler(HandlerType.OnError, new Object[] { key })) { log.Debug($"An unknown error ocurred on WebSocket client ('{key}')"); } OnSessionClosed?.Invoke(key, "WebSocket Error"); }
private async Task HandleSession(ServerSession session) { _sessionManager.InsertSession(session); try { _logger.LogInformation($"A new session connected: {session.SessionId}"); session.OnSessionConnected(); OnSessionConnected?.Invoke(session); try { await session.RunAsync(); } catch (Exception e) { _logger.LogError(e, $"Failed to handle the session {session.SessionId}."); session.Close(); } if (_udpSocket != null) { _udpSocket.RemoveSession(session); } _logger.LogInformation($"The session disconnected: {session.SessionId}"); OnSessionClosed?.Invoke(session); await session.OnSessionClosed(); } catch (Exception e) { _logger.LogError(e, $"Failed to handle the session {session.SessionId}."); } finally { _sessionManager.RemoveSession(session); _sessionFactory.Release(session); } }
public override void OnClose(string connectionGUID, System.Net.WebSockets.WebSocket socket) { WebSocketConnectionManager.RemoveSocket(connectionGUID, socket); ExecuteHandler(HandlerType.OnClose, new Object[] { connectionGUID }); OnSessionClosed?.Invoke(connectionGUID, string.Empty); }
/// <summary> /// 关闭事件处理器 /// </summary> /// <param name="session"></param> /// <param name="closeReason"></param> private void SocketServer_SessionClosed(SuperSocket.SocketBase.AppSession session, SuperSocket.SocketBase.CloseReason closeReason) { ClientsIPEndPoint.Remove(session.RemoteEndPoint); LogHelper.Logger.Info($"SocketServer_SessionClosed,SessionID:{session.SessionID} CloseReason:{closeReason}"); OnSessionClosed?.Invoke(this, new ClosedEventArgs(session.RemoteEndPoint, (CloseReason)(int)closeReason)); }