C++ APISession methods

is_connected

Reports whether the websocket transport is currently open for writing.

is_connected reports whether the websocket transport for the current blaze::session is currently open for writing.

Function variants

bool is_connected() const;

Transport state only

is_connected is a local transport-state check. It does not return blaze::status and does not prove that the session is initialized or authorized.

Result

bool
ValueMeaning
trueWebsocket transport is currently open for writing.
falseSession is not connected right now, or the transport is currently not open for writing.

Behavior notes

  • true means only that the websocket transport is currently open.
  • true does not imply successful initialize, authorization, or panel-events subscription.
  • Before connect(), after shutdown(), and after a final disconnect, this method returns false.
  • During reconnect/resumption windows, transport may temporarily report false.
  • This method is useful for lightweight checks in surrounding application code, but do not use it as a replacement for handling real operation errors.

Example

Compilation note

This example compiles in the same form from C++14 to C++26.

#include "blazeauth/api/api.hpp"

#include <iostream>
#include <string>
#include <system_error>

void print_error_code(const std::string& context, const std::error_code& ec) {
  std::cout << context << ": " << ec.message() << " ("
            << ec.value() << " : " << ec.category().name() << ")\n";
}

int main() {
  blaze::session session;

  std::cout << "Connected before connect(): " << std::boolalpha
            << session.is_connected() << '\n';

  try {
    const blaze::api_server server = session.connect();
    std::cout << "Connected to server location: " << server.location << '\n';
    std::cout << "Connected after connect(): " << session.is_connected() << '\n';

    session.shutdown();
    std::cout << "Connected after shutdown(): " << session.is_connected() << '\n';
  } catch (const std::system_error& e) {
    print_error_code("Connect or shutdown failed", e.code());
    return 1;
  }

  return 0;
}

On this page