To send a message to a counterparty OnixS::FIX::Session::send method must be used. This method is asynchronous. As soon as a session is created it is possible to start sending messages via the session. If the session is not established, the messages will be sent when the connection is established with the counterparty.
To receive incoming application-level messages it is necessary to override the OnixS::FIX::ISessionListener::onInboundApplicationMsg method of OnixS::FIX::ISessionListener class and pass instance of the descendant class to OnixS::FIX::Session's constructor.
#include <OnixS/FIXEngine.h> using namespace OnixS::FIX; using namespace OnixS::FIX::FIX42; class SessionListener : public ISessionListener { public: virtual void onInboundApplicationMsg(const Message& message, Session*) { // Processing incoming application-level message.. std::clog << "Incoming application-level message: " << message.toString() << std::endl; } }; ... const string SENDER_COMP_ID = "AcceptorAndInitiator_SND"; const string TARGET_COMP_ID = "AcceptorAndInitiator_TRG"; const Version VERSION = FIX_42; const string ACCEPTOR_HOST = "localhost"; int ACCEPTOR_PORT = Engine::instance()->getListenPort(); SessionListener listener; Session acceptor(SENDER_COMP_ID, TARGET_COMP_ID, VERSION, &listener); Session initiator(TARGET_COMP_ID, SENDER_COMP_ID, VERSION, &listener); acceptor.logonAsAcceptor(); initiator.logonAsInitiator(ACCEPTOR_HOST, ACCEPTOR_PORT); Message order(Values::MsgType::OrderSingle, VERSION); order.set(Tags::ClOrdID, "20080808-0955789"); order.set( Tags::HandlInst, Values::HandlInst:: AutomatedExecutionOrderPrivateNoBrokerIntervention); order.set(Tags::Symbol, "MSFT"); order.set(Tags::OrderQty, 100000); order.set(Tags::Side, Values::Side::Buy); order.set(Tags::OrdType, Values::OrdType::Market); order.set(Tags::TransactTime, "20051012-22:10:11"); order.validate(); initiator.send(&order); // Continues the message exchange.. // Done with messaging. initiator.logout(); acceptor.logout(); initiator.shutdown(); acceptor.shutdown();