Пример #1
0
        private static void SslAuthenticateAsyncCallback(IAsyncResult ar)
        {
            Tuple <TcpSession, SslStream> state = (Tuple <TcpSession, SslStream>)ar.AsyncState;
            ISession  session = state.Item1;
            TcpServer server  = (TcpServer)session.Server;

            try
            {
                if (server.EnableLog(LogType.Debug))
                {
                    server.Log(LogType.Debug, session, "{0} end ssl Authenticate", session.RemoteEndPoint);
                }
                SslStream sslStream = state.Item2;
                sslStream.EndAuthenticateAsServer(ar);
                EventArgs.ConnectedEventArgs cead = new EventArgs.ConnectedEventArgs();
                cead.Server  = server;
                cead.Session = session;
                server.OnConnected(cead);
                server.BeginReceive(state.Item1);
                if (server.EnableLog(LogType.Debug))
                {
                    server.Log(LogType.Debug, session, "{0} begin receive", session.RemoteEndPoint);
                }
            }
            catch (Exception e_)
            {
                if (server.EnableLog(LogType.Error))
                {
                    server.Error(e_, state.Item1, "create session ssl authenticate callback error {0}", e_.Message);
                }
                session.Dispose();
            }
        }
Пример #2
0
        private void SslAuthenticateAsyncCallback(IAsyncResult ar)
        {
            Tuple <TcpSession, SslStream> state = (Tuple <TcpSession, SslStream>)ar.AsyncState;
            ISession  session = state.Item1;
            TcpServer server  = (TcpServer)session.Server;

            try
            {
                if (server.EnableLog(LogType.Info))
                {
                    server.Log(LogType.Info, session, "{0} end ssl Authenticate", session.RemoteEndPoint);
                }
                SslStream sslStream = state.Item2;
                sslStream.EndAuthenticateAsServer(ar);
                EventArgs.ConnectedEventArgs cead = new EventArgs.ConnectedEventArgs();
                cead.Server  = server;
                cead.Session = session;
                server.OnConnected(cead);
                ((TcpSession)session).SyncSSLData();
                server.BeginReceive(state.Item1);
            }
            catch (Exception e_)
            {
                if (this.EnableLog(LogType.Warring))
                {
                    this.Log(LogType.Warring, state?.Item1, $"create session ssl authenticate callback error {e_.Message}@{e_.StackTrace}");
                }
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }