示例#1
0
        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();
        }
示例#2
0
        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");
        }
示例#3
0
        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);
            }
        }
示例#4
0
 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);
 }
示例#5
0
 /// <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));
 }