Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla StreamingClient

From Leeroopedia
Revision as of 12:15, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/CARLA_simulator_Carla_StreamingClient.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Streaming, Networking
Last Updated 2026-02-15 05:00 GMT

Overview

Client is a streaming client that can subscribe to multiple sensor data streams using TCP connections managed through Boost.Asio.

Description

The Client class in the carla::streaming namespace provides the client-side interface for subscribing to and receiving data from CARLA sensor streams. It wraps a low_level::Client<detail::tcp::Client> implementation and a ThreadPool for asynchronous I/O processing.

The class supports construction with an optional fallback_address string, which is used when the token's address cannot be resolved. The Subscribe method accepts a Token (which identifies a specific stream) and a callback Functor that is invoked each time new data arrives on that stream. The UnSubscribe method stops listening to a specific stream identified by its token.

Execution can be either synchronous via Run() (which blocks the calling thread) or asynchronous via AsyncRun(size_t worker_threads) which spawns the specified number of worker threads. The destructor automatically stops the thread pool.

Important: The class does not support subscribing twice to the same stream, even if the stream is a MultiStream.

Usage

Use this class on the client side (e.g., in the Python API or C++ client) to receive real-time sensor data from a running CARLA server. Create a client, subscribe to streams using tokens obtained from the server, and process incoming data through callbacks.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/streaming/Client.h

Signature

class Client {
public:
    Client() = default;
    explicit Client(const std::string &fallback_address);
    ~Client();

    template <typename Functor>
    void Subscribe(const Token &token, Functor &&callback);

    void UnSubscribe(const Token &token);

    void Run();
    void AsyncRun(size_t worker_threads);

private:
    ThreadPool _service;
    underlying_client _client;
};

Import

#include "carla/streaming/Client.h"

I/O Contract

Inputs

Name Type Required Description
fallback_address const std::string& No Fallback address used if the token's address cannot be resolved
token const Token& Yes Stream token identifying the sensor stream to subscribe to
callback Functor&& Yes Callback function invoked when new data arrives on the stream
worker_threads size_t Yes (AsyncRun) Number of I/O worker threads for asynchronous execution

Outputs

Name Type Description
(callback invocation) void Data is delivered to the subscribed callback function asynchronously

Usage Examples

// Create a streaming client
carla::streaming::Client client("127.0.0.1");

// Subscribe to a sensor stream using a token from the server
client.Subscribe(sensorToken, [](auto buffer) {
    // Process incoming sensor data
    auto data = SensorRegistry::Deserialize(std::move(buffer));
});

// Run asynchronously with 4 worker threads
client.AsyncRun(4);

// Later, unsubscribe from the stream
client.UnSubscribe(sensorToken);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment