private void ConnectedHandler(TcpSocketSaeaSession session) { if (Interlocked.Exchange(ref _currentState, CHANNEL_LOGIN) == CHANNEL_LOGOUT) { this.TcpProxyMainConnectionContext = new TcpProxyMainConnectionContext(session); this.TcpProxyMainConnectionContext.SessionNotifyEventHandler += ProxyMainConnectionSessionNotify; this.TcpProxyMainConnectionContext.LogOutEventHandler += LogOutEventHandler; this.TcpProxyMainConnectionContext.LaunchApplicationConnectEventHandler += LaunchApplicationConnectEventHandler; this.TcpProxyMainConnectionContext.AccessIdOrKeyWrongEventHandler += AccessIdOrKeyWrongEventHandler; session.AppTokens = new object[] { this.TcpProxyMainConnectionContext, ConnectionWorkType.MainApplicationConnection }; this.SendACK(session, ConnectionWorkType.MainApplicationConnection); this.TcpProxyMainConnectionContext.PullSession(); } else { var tcpSessionContext = new TcpSocketSessionContext(session); this._proxySessions.Add(tcpSessionContext.GetHashCode(), tcpSessionContext); session.AppTokens = new object[] { tcpSessionContext, ConnectionWorkType.ApplicationConnection }; this.SendACK(session, ConnectionWorkType.ApplicationConnection); this.SessionNotify(tcpSessionContext, TcpSessionNotify.OnConnected); } }
internal TcpSocketSessionProvider(SessionProviderOptions options) { ApplicationConfiguartion.SetOptions(options); var serverConfig = new TcpSocketSaeaServerConfiguration(); serverConfig.AppKeepAlive = true; serverConfig.CompressTransferFromPacket = false; serverConfig.PendingConnectionBacklog = ApplicationConfiguartion.Options.PendingConnectionBacklog; _server = TcpSocketsFactory.CreateServerAgent(TcpSocketSaeaSessionType.Packet, serverConfig, (notify, session) => { switch (notify) { case TcpSessionNotify.OnConnected: SessionProviderContext sessionBased = new TcpSocketSessionContext(session); this.SessionNotify(sessionBased, TcpSessionNotify.OnConnected); break; case TcpSessionNotify.OnSend: this.SessionNotify(session.AppTokens.First().ConvertTo <SessionProviderContext>(), TcpSessionNotify.OnSend); break; case TcpSessionNotify.OnDataReceiveing: this.SessionNotify(session.AppTokens.First().ConvertTo <SessionProviderContext>(), TcpSessionNotify.OnDataReceiveing); break; case TcpSessionNotify.OnDataReceived: this.SessionNotify(session.AppTokens.First().ConvertTo <SessionProviderContext>(), TcpSessionNotify.OnDataReceived); break; case TcpSessionNotify.OnClosed: this.SessionNotify(session.AppTokens.First().ConvertTo <SessionProviderContext>(), TcpSessionNotify.OnClosed); break; default: break; } }); }