Available languages: [Python](https://databento.com/docs/api-live/client/live-threaded-reconnect.python.md) · [C++](https://databento.com/docs/api-live/client/live-threaded-reconnect.cpp.md) · [Rust](https://databento.com/docs/api-live/client/live-threaded-reconnect.rust.md) · [Raw](https://databento.com/docs/api-live/client/live-threaded-reconnect.raw.md)

Source: https://databento.com/docs/api-live/client/live-threaded-reconnect


### LiveThreaded::Reconnect

Closes the current connection, and attempts to reconnect and authenticate with the gateway.
Allows reestablishing the connection with the Live gateway without creating a new instance of the client.

#### API method

```cpp
void Reconnect();
```

#### Example usage

```cpp
#include <chrono>
#include <databento/exceptions.hpp>
#include <databento/live.hpp>
#include <exception>
#include <vector>

using namespace databento;

std::vector<std::string> symbols = {"CL.c.0"};
auto schema = Schema::Trades;
auto stype_in = SType::Continuous;
auto client = LiveThreaded::Builder()
                  .SetKey("$YOUR_API_KEY")
                  .SetDataset("GLBX.MDP3")
                  .BuildThreaded();
client.Subscribe(symbols, schema, stype_in);
auto record_callback = [](const databento::Record&) {
  return KeepGoing::Continue;
};
auto exc_callback = [&client, &symbols, schema,
                     stype_in](const std::exception& exc) {
  if (dynamic_cast<const TcpError*>(&exc)) {
    // Resubscribe, replaying the last 30 seconds
    auto sys_time = std::chrono::system_clock::now();
    client.Subscribe(symbols, schema, stype_in,
                     sys_time - std::chrono::seconds{30});
    return LiveThreaded::ExceptionAction::Restart;
  }
  return LiveThreaded::ExceptionAction::Stop;
};
// Ignore metadata
client.Start({}, record_callback, exc_callback);
```
