/// <summary> /// Handles incoming messages from local sessions. /// </summary> /// <param name="sender">Local session.</param> /// <param name="e">Formal junk.</param> private void Session_MessageReceived(object sender, EventArgs e) { var session = sender as ActiveSession <T>; if (session.Message == null || (object)session.Message is X690.Message m && m.IsEndSession) { session.Remotes[0].Close(); return; } ClientMessageReceived?.Invoke(sender, new MessageEventArgs <T>(session, session.Message)); ClientBeforeSend?.Invoke(session, new BroadcastMessageArgs <T>(session.Message, 0)); if (session.Remotes[0].IsConnected) { session.Remotes[0].Send(session.Message); } }
/// <summary> /// Handles incoming messages from local sessions. /// </summary> /// <param name="sender">Local session.</param> /// <param name="e">Formal junk.</param> private void Session_MessageReceived(object sender, EventArgs e) { var session = sender as ActiveSession <T>; if (session.Message == null || ((object)session.Message is X690.Message m && m.IsEndSession)) // disconnect requested { foreach (var remote in session.Remotes) { remote.Close(); } return; } ClientMessageReceived?.Invoke(session, new MessageEventArgs <T>(session.Message)); if (session.IsBroadcast) { foreach (var remote in session.Route == 0 ? session.Remotes : session.Remotes.Reverse()) { var toRemoteMessageArgs = new BroadcastMessageArgs <T>(session.Message, remote.Index); ClientBeforeSend?.Invoke(session, toRemoteMessageArgs); if (toRemoteMessageArgs.Message != null) { remote.Send(toRemoteMessageArgs.Message); } } //if (session.Route == 1) // for (int i = 0, n = session.Remotes.Length; i < n; i++) { // var toRemoteMessageArgs = new BroadcastMessageArgs<T>(session.Message, session.Remotes[i].Index); // ClientBeforeSend?.Invoke(session, toRemoteMessageArgs); // if (toRemoteMessageArgs.Message != null) session.Remotes[i].Send(toRemoteMessageArgs.Message); // } //else // for (int i = session.Remotes.Length - 1; i >= 0; i--) { // var toRemoteMessageArgs = new BroadcastMessageArgs<T>(session.Message, session.Remotes[i].Index); // ClientBeforeSend?.Invoke(session, toRemoteMessageArgs); // if (toRemoteMessageArgs.Message != null) session.Remotes[i].Send(toRemoteMessageArgs.Message); // } } else { var toRemoteMessageArgs = new BroadcastMessageArgs <T>(session.Message, session.Route); ClientBeforeSend?.Invoke(session, toRemoteMessageArgs); if (toRemoteMessageArgs.Message != null) { session.Remotes[session.Route].Send(toRemoteMessageArgs.Message); } } }