forwardEstablishing FIX Connection   Table of ContentMessage Sequence Numbersforward
Exchanging Messages
Sending Messages to a Counterparty

To send a message to a counterparty, the Send(Message) 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 are stored in the session storage and will be sent in the replay to the resend request when the connection is established with the counterparty and the sequence numbers mismatch is detected (please see the Resending Messages page).

Receiving Messages from Counterparty

To receive incoming application-level messages, it is necessary to register to the InboundApplicationMsgEvent event.

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

class SessionListener
{
  public void OnInboundApplicationMsg(
    Object sender, InboundApplicationMsgEventArgs args)
  {
    // Processing incoming application-level message.
    Console.WriteLine("Incoming application-level message: {0}", args.Msg);
  }
}

const string senderCompID = "Acceptor";
const string targetCompID = "Initiator";
const ProtocolVersion version = ProtocolVersion.FIX44;
const string host = "localhost";

Engine engine = Engine.Init();

using (Session acceptor =
  new Session(senderCompID, targetCompID, version))
{
  acceptor.LogonAsAcceptor();

  using (Session initiator =
    new Session(targetCompID, senderCompID, version))
  {
    initiator.LogonAsInitiator(host, Engine.Instance.Settings.ListenPort);

    SessionListener listener = new SessionListener();
    initiator.InboundApplicationMsgEvent +=
    new Session.InboundApplicationMsgEventHandler(listener.OnInboundApplicationMsg);

    Message order = new Message(MsgType.NewOrderSingle, version);

    order.Set(Tags.ClOrdID, "Unique identifier for Order as assigned by the buy-side");
    order.Set(Tags.HandlInst, "1");
    order.Set(Tags.Symbol, "Ticker symbol");
    order.Set(Tags.Side, "1");
    order.Set(Tags.TransactTime, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"));
    order.Set(Tags.OrdType, "1");

    order.Validate();

    initiator.Send(order);

    // Continues the message exchange.

    // Done with messaging.
    initiator.Logout();
  }

  acceptor.Logout();
}

engine.Shutdown();
VB
Imports FIXForge.NET.FIX
Imports FIXForge.NET.FIX.FIX44

Class SessionListener
Public Sub OnInboundApplicationMsg(ByVal sender As Object, ByVal args As InboundApplicationMsgEventArgs)
  ' processing of the application-level incoming message.
  Console.WriteLine("Incoming application-level message: {0}", args.Msg)
End SubEnd Class

Dim senderCompID As String = "Acceptor"
Dim targetCompID As String = "Initiator"
Dim fixVersion As FIXForge.NET.FIX.ProtocolVersion = FIXForge.NET.FIX.ProtocolVersion.FIX44
Dim host As String = "localhost"

Dim fixEngine As Engine = Engine.Init()

Dim acceptor As Session = New Session(senderCompID, targetCompID, fixVersion)
acceptor.LogonAsAcceptor()

Dim initiator As Session = New Session(targetCompID, senderCompID, fixVersion)
initiator.LogonAsInitiator(host, Engine.Instance.Settings.ListenPort)

Dim listener As SessionListener = New SessionListener()

AddHandler session.InboundApplicationMsgEvent, AddressOf listener.OnInboundApplicationMsg

Dim order As Message = New Message(MsgType.NewOrderSingle, fixVersion)

order.Set(Tags.ClOrdID, "Unique identifier for Order as assigned by the buy-side")
order.Set(Tags.HandlInst, "1")
order.Set(Tags.Symbol, "Ticker symbol")
order.Set(Tags.Side, "1")
order.Set(Tags.TransactTime, DateTime.UtcNow.ToString("yyyyMMdd-HH:mm:ss"))
order.Set(Tags.OrdType, "1")

order.Validate()

initiator.Send(order)

' Continues the message exchange.

' Done with messaging.
initiator.Logout()
acceptor.Logout()

acceptor.Dispose()
initiator.Dispose()

fixEngine.Shutdown()