开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: C++ preventing EReader reading when socket is closed


 

On restarting the TWS Application manually from TWS Application drop down menu while TWS API process is up & running?
TWS Api replies with Connection Closed callback via

Updated source code


void Connect() {
? if (m_pClient && m_pClient->isConnected())? ?m_pClient->eDisconnect();
?
? bool bRes = m_pClient->eConnect((const char*)host_ip.c_str(), host_port,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? clientId, m_extraAuth);
? bool connection_result = m_pClient->isConnected();
? if (bRes && connection_result) {
? ? printf("Connected to %s:%d clientId:%d\n", m_pClient->host().c_str(),
? ? ? ? ? ?m_pClient->port(), clientId);
? ??
? ? if (m_pClient && m_pClient->isConnected()) {
? ? ? m_pReader = std::unique_ptr<EReader>(new EReader(m_pClient, &m_osSignal));
? ? ? if (m_pReader)? m_pReader->start();
? ? ? ?else {
? ? ? ? std::cout << "Failed to create EReader instance\n";
? ? ? ? exit(1);
? ? ? }
? ? } else {
? ? ? std::cout << "Client is not connected. Cannot create EReader\n";
? ? ? exit(1);
? ? }
? } else {
? ? printf("Cannot connect to %s:%d clientId:%d\n", m_pClient->host().c_str(),
? ? ? ? ? ?m_pClient->port(), clientId);
? ? exit(1);
? }
? return;
}


void connectionClosed()
{
?std::this_thread::sleep_for(std::chrono::seconds(30));
?Connect();??
}


Response received on simulating above mentioned activity

Join [email protected] to automatically receive all group messages.