Пример #1
0
        void Handshake(object o)
        {
            MessageConnection connection = o as MessageConnection;

            try
            {
                if (connection.SessionID() != _ConnectionSessionID)
                {
                    STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake Undeliverable to " + connection.RemoteAddress + ".", Sys.EventLog.EventLogEntryType.Information);

                    if (onHandshakeComplete != null)
                    {
                        connection.Close();
                    }

                    return;
                }

                int port = connection.LocalPort;
                if (connection.ConnectionRole == Role.Server)
                {
                    port = connection.RemotePort;
                }

                STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Performing handshake with " + connection.RemoteAddress + ":" + port + ".", Sys.EventLog.EventLogEntryType.Information);

                Message response = connection.Send(this, TimeSpan.FromSeconds(15));

                if (response is Timeout)
                {
                    if (connection.SessionID() != _ConnectionSessionID)
                    {
                        STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake Undeliverable to " + connection.RemoteAddress + ":" + port + ".", Sys.EventLog.EventLogEntryType.Information);
                    }
                    else
                    {
                        STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake timeout with " + connection.RemoteAddress + ":" + port + ".", Sys.EventLog.EventLogEntryType.Information);
                    }

                    if (onHandshakeComplete != null)
                    {
                        connection.Close();
                    }

                    return;
                }

                if (response is Undeliverable)
                {
                    STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake Undeliverable to " + connection.RemoteAddress + ":" + port + ".", Sys.EventLog.EventLogEntryType.Information);

                    if (onHandshakeComplete != null)
                    {
                        connection.Close();
                    }

                    return;
                }

                if (onHandshakeComplete != null)
                {
                    try
                    {
                        onHandshakeComplete(this, connection);
                    }
                    catch { }
                }

                STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake completed with " + connection.RemoteAddress + ":" + port + ".", Sys.EventLog.EventLogEntryType.Information);
            }
            catch
            {
                if (connection.SessionID() == _ConnectionSessionID)
                {
                    connection.Close();
                }
            }
        }
Пример #2
0
        public void PerformHandshake(MessageConnection connection)
        {
            _ConnectionSessionID = connection.SessionID();

            STEM.Sys.Global.ThreadPool.RunOnce(new System.Threading.ParameterizedThreadStart(Handshake), connection);
        }