Accepting FIX Session Without a Prior Creation of Session Object : OnixS .NET FIX Engine
forwardThreading model   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 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 new Session object and call the LogonAsAcceptor() method to establish connection. Required Session constructor parameters can be filled from 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.

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

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

  Session createdSession = new Session(logonMessage[Tags.TargetCompID], logonMessage[Tags.SenderCompID], logonMessage.Dialect);

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

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

void OnUnknownIncomingConnection(Object sender, Engine.UnknownIncomingConnectionEventArgs e)
{
  e.RejectReason = "Session rejected.";
}