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.
To handle such connection attempts, subscribe to the UnknownIncomingConnection event.
To accept the incoming connection, create a new Session object and call the LogonAsAcceptor() method to establish the FIX connection. Session constructor parameters can be taken from the incoming Logon message.
To decline the incoming connection, no action is needed. If the RejectReason
parameter is set, then the Engine
will use it as the value of the Text
field
in the Logout message.
For example:
// Accept:
Engine.Instance.UnknownIncomingConnection += (object sender, UnknownIncomingConnectionEventArgs e) =>
{
var logon = e.IncomingLogonMessage;
var session = new Session(logon[Tag.TargetCompID], logon[Tag.SenderCompID], logon.Version);
Console.WriteLine($"Accepted unknown incoming connection: {session}");
session.LogonAsAcceptor();
};
// Reject and specify the reject reason:
Engine.Instance.UnknownIncomingConnection += (object sender, UnknownIncomingConnectionEventArgs e) =>
{
e.RejectReason = "Unknown incoming connections are rejected";
};