Author |
Topic: GF COM API Reconnecting on Socket Error Disconnection (5 messages, Page 1 of 1) |
||||
---|---|---|---|---|---|
Moderators: VPfau | |||||
RWare2020 Posts: 206 Joined: Feb 11, 2020 |
I am wondering the correct steps to reconnect to the API when being disconnected.
I am currently just trying to attempt to login the same way I do when initially logging in like this: IConnectionContextBuilderPtr builder; builder.CreateInstance(__uuidof(ConnectionContextBuilder)); builder->WithUserName(user); builder->WithPassword(pass); builder->WithHost(url); builder->WithUUID(uuid); builder->WithPort(9210); builder->WithForceLogin(); GFApi()->Connection->Aggregate->Connect(builder->Build()); I then get a callback to OnLoginFailed with the fail reason of FailReason_InvalidUserOrPassword I am using the same user and password as when I login initially. Here is the log when I reconnect with all timestamps in MST: Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: OrderConnection Connecting to sim.gainfutures.com:9210 Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: OrderConnection Outgoing: Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: PriceConnection Connecting to sim.gainfutures.com:9211 Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: PriceConnection Outgoing: Timestamp: 5/4/2021 4:07:22 PM - Category: 0 - Message: OrderConnection Disconnected: System.Exception: by request Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: PriceConnection Disconnected: System.Exception: by request Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: Received AuthChallenge from Gain Futures Price Server v4.1.0.0 Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: Received AuthChallenge from Gain Futures Order Server v4.1.0.0 |
||||
SPikalov Posts: 25 Joined: |
Hello.
It is difficult to understand what went wrong, according to the available information. Please provide a more detailed code example and UserName under which you connect. Regards, Sergey |
||||
RWare2020 Posts: 206 Joined: Feb 11, 2020 |
When logging into the API I use this code:
I am wondering the correct steps to reconnect to the API when being disconnected. I am currently just trying to attempt to login the same way I do when initially logging in like this: IConnectionContextBuilderPtr builder; builder.CreateInstance(__uuidof(ConnectionContextBuilder)); builder->WithUserName(TNT2); builder->WithPassword(pass); builder->WithHost("sim.gainfutures.com"); builder->WithUUID(uuid); builder->WithPort(9210); builder->WithForceLogin(); GFApi()->Connection->Aggregate->Connect(builder->Build()); When I get disconnected from the API from a socket error. I get a callback into OnDisconnected in which I run this code again: IConnectionContextBuilderPtr builder; builder.CreateInstance(__uuidof(ConnectionContextBuilder)); builder->WithUserName(TNT2); builder->WithPassword(pass); builder->WithHost("sim.gainfutures.com"); builder->WithUUID(uuid); builder->WithPort(9210); builder->WithForceLogin(); GFApi()->Connection->Aggregate->Connect(builder->Build()); I then get a callback to OnLoginFailed for the fail reason of FailReason_InvalidUserOrPassword. I use the exact same username and password as I use when I initially login. Here is the log from OnNewMessageLogged callback when I reconnect with all timestamps in MST: Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: OrderConnection Connecting to sim.gainfutures.com:9210 Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: OrderConnection Outgoing: Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: OrderConnection Connected to 64.94.37.238 Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: PriceConnection Connecting to sim.gainfutures.com:9211 Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: PriceConnection Outgoing: Timestamp: 5/4/2021 4:07:10 PM - Category: 2 - Message: PriceConnection Connected to 64.94.37.238 Timestamp: 5/4/2021 4:07:22 PM - Category: 0 - Message: OrderConnection Disconnected: System.Exception: by request Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: PriceConnection Disconnected: System.Exception: by request Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: Received AuthChallenge from Gain Futures Price Server v4.1.0.0 Timestamp: 5/4/2021 4:08:54 PM - Category: 0 - Message: Received AuthChallenge from Gain Futures Order Server v4.1.0.0 |
||||
SPikalov Posts: 25 Joined: |
Probably your issue here is that you are trying to call Connect from the Disconnected event handler.
You need to wait for the current process to complete. For example, in “GF API COM C++ Sample” I did it like this: void __stdcall CCppCOMSampleDlg::OnDisconnected(GF_Api_COM::DisconnectionReason reason, BSTR message) { std::thread::id this_id = std::this_thread::get_id(); CString string(message); log << "Disconnected due to " << string < //----Emulating the repeated click of the button by the user HWND btnConnetHandle = GetDlgItem(IDC_CONNECT)-> GetSafeHwnd(); ::PostMessage(btnConnetHandle, BM_CLICK, 0, 0); } |
||||
RWare2020 Posts: 206 Joined: Feb 11, 2020 |
That worked. Thank you very much.
|
||||