forwardFIX Session   Table of ContentExchanging Messagesforward
Establishing FIX Connection
Establishing Connection

To establish a FIX connection as an Acceptor, the LogonAsAcceptor() method must be used.

To establish a FIX connection as an Initiator, the LogonAsInitiator(String, Int32) method must be used.

Closing a Connection

To disconnect the session, the Logout() method must be used. This member implements a graceful closing of the FIX connection as defined by the Standard.

Note Note
LogonAsInitiator(String, Int32) and Logout() methods are blocked until the Logon/Logout response is received. These methods have a timeout during which the response should be received. This timeout is equal to the heartbeat interval (by default 30 sec) + ReasonableTransmissionTime value (by default 20%) as a percentage from the heartbeat interval. If the acknowledgment Logon/Logout message is not received during the timeout then the Logout message will be sent and the FIX connection will be closed.
Reconnection Facility

When a FIX session is in the active state and there are some network issues the FIX Engine will try to restore the FIX connection in accordance with ReconnectAttempts and ReconnectInterval settings.

Note Note
Reconnection facility works for already established connections. In other cases, you need to use the Sessions Scheduler component or manually handle LinkErrorException or TimeoutException exceptions of LogonAsInitiator(String, Int32) method and try to connect again.

Example
C#
using FIXForge.NET.FIX;
using FIXForge.NET.FIX.FIX44;

const string senderCompID = "SenderCompID";
const string targetCompID = "TargetCompID";
const ProtocolVersion version = ProtocolVersion.FIX44;

const string TARGET_HOST = "localhost";

// Target port is equal to acceptor's port to create a loopback FIX session.
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();
}
VB
Imports  FIXForge.NET.FIX
Imports  FIXForge.NET.FIX.FIX44

Dim senderCompID As String = "SenderCompID"
Dim targetCompID As String = "TargetCompID"

Dim fixVersion As FIXForge.NET.FIX.ProtocolVersion = FIXForge.NET.FIX.ProtocolVersion.FIX44

Dim TARGET_HOST As 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.

See Also