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

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


### LiveBlocking::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 <databento/exceptions.hpp>
#include <databento/live.hpp>
#include <exception>
#include <iostream>

using namespace databento;

auto client = LiveBlocking::Builder()
                  .SetKey("$YOUR_API_KEY")
                  .SetDataset("GLBX.MDP3")
                  .BuildBlocking();
client.Subscribe({"CL.c.0"}, Schema::Trades, SType::Continuous);
auto metadata = client.Start();
for (int32_t i = 0; i < 10; ++i) {
  try {
    [[maybe_unused]] auto record = client.NextRecord();
  } catch (const databento::TcpError& error) {
    std::cerr << "Caught TCP error: " << error.what()
              << "\nAttempting reconnect\n";
    client.Reconnect();
  } catch (const std::exception& exc) {
    std::cerr << "Caught unknown exception: " << exc.what()
              << "\nShutting down\n";
    client.Stop();
  }
}
```
