forwardUpdating GUI Controls on Session Event   Table of ContentConnecting using Custom Logon Messageforward
Accepting FIX Session Without a Prior Creation of Session Object

Sometimes there is a requirement to accept an incoming FIX session 'on the fly' without the prior creation of the Session object. This often happens when an unknown session-initiator is trying to connect to the Engine. For this reason, OnixS .NET Framework FIX Engine exposes an ability to accept such connection by creating a generic session-acceptor. To take advantage of this feature, it is necessary to subscribe to the UnknownIncomingConnection event.

To accept the incoming connection, create a new Session object and call the LogonAsAcceptor() method to establish a connection. Required Session constructor parameters can be filled from the incoming logon message.

To decline the incoming connection, no action is needed. The only thing to do is to set the RejectReason parameter and the Engine will use it as text in logout message.

Also, there is an ability to validate an incoming FIX connection even if the corresponding acceptor session is present. It can be done in the IncomingConnection event that is called when an incoming logon message is received but before the corresponding acceptor session is found. To decline the incoming connection, you need to set the RejectReason parameter, and the Engine will use it as a text in the logout message.

Additionally, there is an ability to validate incoming TCP connections before receiving any messages to reject unwanted ones by IP address and port. It can be done in the IncomingTelecommunicationLink event that is called when an incoming TCP connection is detected. To decline the incoming TCP connection, you need to set the RejectReason parameter, and the Engine will reject it.

Example
C#
void run()
{
  // ..
  Engine.Instance.UnknownIncomingConnection += new Engine.UnknownIncomingConnectionEventHandler(OnUnknownIncomingConnection);
  // ..
}

void OnUnknownIncomingConnection(Object sender, Engine.UnknownIncomingConnectionEventArgs args)
{
  FlatMessage logonMessage = args.IncomingLogonMessage;

  Session createdSession = new Session(logonMessage.Get(logonMessage.Find(Tags.TargetCompID)), logonMessage.Get(logonMessage.Find(Tags.SenderCompID)), logonMessage.Version());

  Console.WriteLine("Accepting unknown incoming Session {0}.", createdSession);

  createdSession.LogonAsAcceptor();
}
C#
void run()
{
  // ..
  Engine.Instance.UnknownIncomingConnection += new Engine.UnknownIncomingConnectionEventHandler(OnUnknownIncomingConnection);
  Engine.Instance.IncomingConnection += new Engine.IncomingConnectionEventHandler(OnIncomingConnection);
  Engine.Instance.IncomingTelecommunicationLink += new Engine.IncomingTelecommunicationLinkEventHandler(OnIncomingTelecommunicationLink);
  // ..
}

void OnUnknownIncomingConnection(Object sender, Engine.UnknownIncomingConnectionEventArgs args)
{
   // Once the session is rejected, the Engine will send the logout message.
   // The Engine will use the reject reason as a text in the logout message.
   args.RejectReason = "Session rejected in UnknownIncomingConnection event.";
}

void OnIncomingConnection(Object sender, Engine.IncomingConnectionEventArgs args)
{
   // Once the session is rejected, the Engine will send the logout message.
   // The Engine will use the reject reason as a text in the logout message.
   args.RejectReason = "Session rejected in IncomingConnection event.";
}

void OnIncomingTelecommunicationLink(Object sender, Engine.IncomingTelecommunicationLinkEventArgs args)
{
   // Once the TCP connection is rejected, the Engine will close it.
   args.RejectReason = "TCP connection rejected in IncomingTelecommunicationLink event.";
}