0

I'm new to QuickFIXn and trying to implement a initiator for FIX5.0SP2. I'm created config and sample code as below. But when I run the application, I can only see OnCreate(Session) method called. The client is not gettign connected to the server and neither any Logon is sent. I think I've exhausted all my options to know why there is no connection and logon. Can someone please help out, it's very basic but I really don't know what I'm missing.

[DEFAULT]
ConnectionType=initiator
ReconnectInterval=10
FileStorePath=store
FileLogPath=log
StartTime=00:00:00
EndTime=23:55:00
UseDataDictionary=Y
TransportDataDictionary=C:\Users\<someuser>\source\repos\FIX-Client\FIX-Client\dict\FIXT11.xml
AppDataDictionary=C:\Users\<someuser>\source\repos\FIX-Client\FIX-Client\dict\FIX50SP2.xml
SocketConnectHost=101.1.2.3
LogoutTimeout=10
ResetOnLogon=Y
ResetOnDisconnect=Y
DefaultApplVerID=FIX.5.0SP2


[SESSION]
# inherit ConnectionType, ReconnectInterval and SenderCompID from default
BeginString=FIXT.1.1
SocketConnectPort=4000
SenderCompID=ABC
TargetCompID=ACCEPT
HeartBtInt=30

And here is the implementation

  String settingFile = "../../fixApp.cfg";
        SessionSettings settings = new SessionSettings(settingFile);
        IApplication fixApp = new QuickFixClient();
        IMessageStoreFactory storeFactory = new FileStoreFactory(settings);
        ILogFactory logFactory = new FileLogFactory(settings);
        QuickFix.Transport.SocketInitiator initiator = new QuickFix.Transport.SocketInitiator(fixApp, 
            storeFactory, settings, logFactory);

        initiator.Start();
        
        SessionID sessionId = new SessionID("FIXT.1.1", "XYZ", "ACCEPT");
       
        Console.WriteLine(initiator.IsLoggedOn); // returns False
        Session.LookupSession(sessionId).Logon(); // Throws Null pointer exception
user85
  • 1,526
  • 5
  • 26
  • 42
  • 1
    You're getting a null reference in the last line of your code snippet because you're looking up session with SenderCompID "XYZ", but your config file only defines a session with SenderCompID "ABC", hence `Session.LookupSession()` returns `null`. Using your code I see connection attempts being made to the target, so either there's nothing listening on the target host/port, or connections are being blocked somewhere along the path. – Iridium Apr 21 '23 at 19:41
  • @Iridium, thanks for pointing out , but I did so because - 1. I don't know how to fetch the ABC session that is being created via config setting, and 2. After reading QuickFIx documentation , my understanding was sessions can also be created as I did for XYZ (new SessionID("FIXT.1.1", "XYZ", "ACCEPT");). Do I need to correct any of the code or you think it should work , I checked the target host and port and they are accepting connection from another tool from same machine but from my code I'm unable to connect. – user85 Apr 22 '23 at 16:45
  • 1
    The code seemed to work fine without the last line - it's not necessary to explicitly logon a session. Providing it's within session's start-end time and the initiator is started, it will make repeated connection attempts until it is successfully connected. Sessions are ordinarily created via config (the `[SESSION]` section(s) of the config file), you simply created a session **ID**, which is basically just a _name_ for a session - that is not the same as creating a session itself. – Iridium Apr 22 '23 at 18:45
  • Thanks @Iridium, it is working well , probably the host was not accepting connection the other day when I was trying. However one more change I did today was to set the ReconnectInterval=1 instead of 10, just incase if this is useful information for others. – user85 Apr 24 '23 at 06:00

0 Answers0