OnixS C++ FIX Engine  4.5.0
API Documentation
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 OnixS::FIX::Session object. This often happens when an unknown session-initiator is trying to connect to Engine. For this reason, OnixS C++ FIX Engine exposes an ability to accept such a connection by creating a temporary session-acceptor and to respond to the counterparty. To take advantage of this feature, it is necessary to inherit from the OnixS::FIX::IEngineListener class, to overwrite the OnixS::FIX::IEngineListener::onUnknownIncomingConnection method, and register isntance of inherited listener with the OnixS::FIX::Engine instance, using the OnixS::FIX::Engine::registerListener method.

To accept the incoming connection, create the new OnixS::FIX::Session object, and call the OnixS::FIX::Session::logonAsAcceptor method to establish the connection. The required OnixS::FIX::Session constructor parameters can be filled from the incomingLogon message.

To decline the incoming connection, no action is needed. One thing, that you can do, is to set the rejectReason parameter and Engine will use it as a text in the logout message.

Example

using namespace OnixS::FIX;
using namespace OnixS::FIX::FIX42;
class UnknownSessionAcceptor : public IEngineListener, public ISessionListener
{
public:
UnknownSessionAcceptor(bool acceptConnection, const std::string& rejectReason)
: acceptConnection_(acceptConnection)
, rejectReason_(rejectReason)
, session_(NULL)
{
}
virtual ~UnknownSessionAcceptor()
{
delete session_;
}
void onUnknownIncomingConnection(const FlatMessage & incomingLogon, const int /*listenPort*/, const int /*counterpartyPort*/, const std::string& /*counterpartyIpAddress*/, std::string * rejectReason) ONIXS_FIXENGINE_OVERRIDE
{
if (acceptConnection_)
{
session_ = new Session(incomingLogon[incomingLogon.find(Tags::TargetCompID)].toString() , incomingLogon[incomingLogon.find(Tags::SenderCompID)].toString(), Dictionary(ProtocolVersion::FIX_42), this);
session_->logonAsAcceptor();
}
else
{
// Once session is rejected, Engine will send logout message.
// Engine will use reject reason as text in logout message.
if (rejectReason_ != "")
{
*rejectReason = rejectReason_;
}
}
}
void onInboundApplicationMsg(Message&, Session*) ONIXS_FIXENGINE_OVERRIDE
{
// Process incoming messages in the same way as working with usual sessions.
}
void onError(EngineErrorReason::Enum, const std::string& description) ONIXS_FIXENGINE_OVERRIDE
{
std::clog << "Engine ERROR: " << description << std::endl;
}
void onWarning(EngineWarningReason::Enum, const std::string& description) ONIXS_FIXENGINE_OVERRIDE
{
std::clog << "Engine WARNING: " << description << std::endl;
}
void onError(ErrorReason::Enum, const std::string & description, Session *) ONIXS_FIXENGINE_OVERRIDE
{
std::clog << "Session ERROR: " << description << std::endl;
}
void onWarning(WarningReason::Enum, const std::string & description, Session *) ONIXS_FIXENGINE_OVERRIDE
{
std::clog << "Session WARNING: " << description << std::endl;
}
private:
bool acceptConnection_;
std::string rejectReason_;
};
UnknownSessionAcceptor unknownSessionAcceptor(true, "");
Engine::instance()->registerListener(&unknownSessionAcceptor);