Implementation:CARLA simulator Carla StreamingEndPoint
| Knowledge Sources | |
|---|---|
| Domains | Streaming, Networking |
| Last Updated | 2026-02-15 05:00 GMT |
Overview
EndPoint provides template-based network endpoint abstraction with factory functions for creating fully-defined and partially-defined TCP/UDP endpoints used by the CARLA streaming framework.
Description
The EndPoint template system in carla::streaming::detail offers two specializations:
FullyDefinedEndPoint wraps a boost::asio::ip::basic_endpoint<Protocol> with both an address and a port. It provides address() and port() accessors and an implicit conversion operator back to the Boost.Asio endpoint type.
PartiallyDefinedEndPoint stores only a port number (uint16_t) and defaults to IPv4 (Protocol::v4()) when converted to a Boost.Asio endpoint. This is useful when binding to all interfaces on a specific port.
The file also provides several free factory functions in the carla::streaming namespace:
- make_localhost_address() returns the loopback address 127.0.0.1
- make_address(const std::string&) resolves a hostname or IP string to an address using boost::asio::ip::tcp::resolver, falling back to boost::asio::ip::make_address if resolution yields no results
- make_endpoint<Protocol>(...) overloads create either fully-defined or partially-defined endpoints from various combinations of address strings, boost::asio::ip::basic_endpoint objects, and port numbers
Usage
These endpoint utilities are used internally by Server and Router classes to configure TCP listen addresses and construct connection targets. The make_endpoint factory functions provide a clean interface for building endpoints from different input formats.
Code Reference
Source Location
- Repository: CARLA
- File:
LibCarla/source/carla/streaming/EndPoint.h
Signature
namespace detail {
struct FullyDefinedEndPoint {};
struct PartiallyDefinedEndPoint {};
template <typename Protocol, typename EndPointType>
class EndPoint;
// Specialization: FullyDefinedEndPoint
template <typename Protocol>
class EndPoint<Protocol, FullyDefinedEndPoint> {
public:
explicit EndPoint(boost::asio::ip::basic_endpoint<Protocol> ep);
auto address() const;
uint16_t port() const;
operator boost::asio::ip::basic_endpoint<Protocol>() const;
};
// Specialization: PartiallyDefinedEndPoint
template <typename Protocol>
class EndPoint<Protocol, PartiallyDefinedEndPoint> {
public:
explicit EndPoint(uint16_t port);
uint16_t port() const;
operator boost::asio::ip::basic_endpoint<Protocol>() const;
};
}
// Factory functions
static inline auto make_localhost_address();
static inline auto make_address(const std::string &address);
template <typename Protocol>
static inline auto make_endpoint(boost::asio::ip::basic_endpoint<Protocol> ep);
template <typename Protocol>
static inline auto make_endpoint(const char *address, uint16_t port);
template <typename Protocol>
static inline auto make_endpoint(const std::string &address, uint16_t port);
template <typename Protocol>
static inline auto make_endpoint(uint16_t port);
Import
#include "carla/streaming/EndPoint.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| address | const std::string& / const char* | No | IP address or hostname string to resolve |
| port | uint16_t | Yes | Port number for the endpoint |
| ep | boost::asio::ip::basic_endpoint<Protocol> | No | Pre-existing Boost.Asio endpoint to wrap |
Outputs
| Name | Type | Description |
|---|---|---|
| (make_endpoint result) | EndPoint<Protocol, ...> | A fully or partially defined endpoint object |
| (make_address result) | boost::asio::ip::address | Resolved IP address from hostname or IP string |
Usage Examples
using protocol_type = boost::asio::ip::tcp;
// Create endpoint from address and port
auto ep = carla::streaming::make_endpoint<protocol_type>("192.168.1.100", 2000);
// Create endpoint with port only (binds to all interfaces via IPv4)
auto ep_any = carla::streaming::make_endpoint<protocol_type>(2000);
// Resolve an address string
auto addr = carla::streaming::make_address("my-server.local");
// Get localhost address
auto localhost = carla::streaming::make_localhost_address();