Establishing Connection
To establish the a FIX connection as an Acceptor the LogonAsAcceptor()()() method must be used.
To establish the a FIX connection as an Initiator the LogonAsInitiator(String, Int32) method must be used.
Closing a Connection
To disconnect the session Logout()()() method must be used. This member implements a graceful closing of the FIX connection as defined by the Standard.
Example
using FIXForge.NET.FIX; using FIXForge.NET.FIX.FIX42; const string senderCompID = "SenderCompID"; const string targetCompID = "TargetCompID"; const ProtocolVersion version = ProtocolVersion.FIX42; const string TARGET_HOST = "localhost"; // Target port is equal to acceptor's port to create a loopback FIX session. const int TARGET_PORT = Engine.Instance.Settings.ListenPort; // Use of 'using' statement is more convenient for cases // like this example since it will dispose session automatically // even if exception occurs. using (Session acceptor = new Session(senderCompID, targetCompID, version)) { acceptor.LogonAsAcceptor(); using (Session initiator = new Session(targetCompID, senderCompID, version)) { // Sends the Logon message and waits for the acknowledgment Logon. initiator.LogonAsInitiator(TARGET_HOST, TARGET_PORT); // Message exchange and processing logic goes here.. // Sends the Logout message and waits for the confirming Logout. initiator.Logout(); } acceptor.Logout(); }
Imports FIXForge.NET.FIX Imports FIXForge.NET.FIX.FIX42 Dim senderCompID As String = "SenderCompID" Dim targetCompID As String = "TargetCompID" Dim fixVersion As FIXForge.NET.FIX.ProtocolVersion = FIXForge.NET.FIX.ProtocolVersion.FIX42 Dim TARGET_HOSTAs String = "localhost" ' Target port is equal to acceptor's port to create a loopback FIX session. Dim TARGET_PORT As Integer = Engine.Instance.Settings.ListenPort Dim acceptor As New Session(senderCompID, targetCompID, fixVersion) Dim initiator As New Session(targetCompID, senderCompID, fixVersion) acceptor.LogonAsAcceptor() ' Sends the Logon message and waits for the acknowledgment Logon. initiator.LogonAsInitiator(TARGET_HOST, TARGET_PORT) ' Message exchange and processing logic goes here.. ' Sends the Logout message and waits for the confirming Logout. acceptor.Logout() initiator.Logout() ' Don't forget to perform cleanup. acceptor.Dispose() initiator.Dispose()
Connection and Session Lifetime
A single FIX session can exist across multiple sequential (not concurrent) physical connections. Parties can connect and disconnect multiple times while maintaining a single FIX session. That is, once the Logout()()() method is called, the FIX Connection is terminated however the FIX session life continues. It is possible to continue the same session later using either LogonAsAcceptor()()() or LogonAsInitiator(String, Int32) methods again. In other words, a FIX Session is comprised of one or more FIX connections.