public virtual bool Respond(Message message) { if (MessageConnection != null) { return(MessageConnection.Send(new Response(this, message))); } else { return(false); } }
void Handshake(object o) { MessageConnection connection = o as MessageConnection; STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Performing handshake with " + connection.RemoteAddress + ".", Sys.EventLog.EventLogEntryType.Information); int retry = 0; Message response = connection.Send(this, TimeSpan.FromSeconds(10)); while ((response is Timeout) && (retry < 5)) { STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake timeout with " + connection.RemoteAddress + ".", Sys.EventLog.EventLogEntryType.Information); response = connection.Send(this, TimeSpan.FromSeconds(10)); retry++; } if (response is Timeout || response is Undeliverable) { connection.Close(); return; } STEM.Sys.EventLog.WriteEntry("ConnectionType.Handshake", "Handshake completed with " + connection.RemoteAddress + ".", Sys.EventLog.EventLogEntryType.Information); }
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(); } } }