Engine::Session* Engine::FixEngine::createSession(Engine::Application* apApp, const std::string& aSenderCompID, const std::string& aTargetCompID, Engine::FIXVersion aVer = FIX42, Engine::SessionExtraParameters* pParam = NULL, const Engine::MessageStorageType storageType = persistent_storageType)
After session is created use one of the methods below to connect it as initiator.
void Engine::Session::connect(int HBI, const std::string& host, int port)
void Engine::Session::connect(int HBI, const FIXMessage& logonMsg, const std::string &host, int port)
For example:
#include <iostream> #include <B2BITS_V12.h> using namespace std; class Appl : public Engine::Application { // See "Application description" section }; try { // initialization Engine::FixEngine::init(); Appl appl; // create a session for FIX 4.2 Engine::Session* pSn = Engine::FixEngine::singleton()->createSession( &appl, "SENDER", "TARGET", Engine::FIX42); // establish the session as initiator pSn->connect(30, "localhost", 9106) // ... - business logic // terminate the FIX session pSn->disconnect(); // it is vital to do this before the 'release' call pSn->registerApplication(NULL); // release resources pSn->release(); FixEngine::destroy(); } catch(const Exception& ex) { cout << "EXCEPTION: " << ex.what() << endl; }
There is no need to wait until connection is established to send messages. If connection is not established messages will be sent later after connection process succeeds (for more information refer to Late delivery vs rejecting).
For example:
Appl appl; // : see the Application class above Engine::FIXVersion version = Engine::FIX42; // create session Engine::Session* pSession = Engine::FixEngine::singleton()->createSession(&appl, "sender", "target", version); // create Logon message framework Engine::FIXMessage* pLogonMsg = Engine::FIXMsgFactory::singleton()->newLogonSkel(version); // sets fields pLogonMsg->set(Engine::FIXField::MaxMessageSize, 20000); // tag 383 // establishes the session as initiator pSession->connect(0, *pLogonMsg, "localhost", 9105);
Number of reconnection attempts and delay can be set in properties file (see Reconnect.MaxTries and Reconnect.Interval). Refer to Configuration for more details.
Engine::Session::disconnect(bool aMarkAsTerminated = true)
Engine::Session::disconnect(const std::string &aLogoutText, bool aMarkAsTerminated=true)
aMarkAsTerminated parameter is used to set the desired state after disconnection. If it is set to "true" initiator tries to disconnect gracefully (i.e. execute logout procedure). If it is set to "false" initiator moves to the non-gracefully terminated state.
It is vital to call Engine::Session::registerApplication(NULL) before calling the release method.
It is vital to call the Engine::Session::release() method only once for the given session.
All session level messages are send automatically when needed.
1.5.6