Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocol::tcp Namespace Reference

Functions

auto create_connection (std::string_view id="") -> std::unique_ptr< unified::i_connection >
 Creates a TCP connection (not yet connected)
 
auto connect (const unified::endpoint_info &endpoint, std::string_view id="") -> std::unique_ptr< unified::i_connection >
 Creates and connects a TCP connection in one call.
 
auto connect (std::string_view url, std::string_view id="") -> std::unique_ptr< unified::i_connection >
 Creates and connects a TCP connection using URL format.
 
auto create_listener (std::string_view id="") -> std::unique_ptr< unified::i_listener >
 Creates a TCP listener (not yet listening)
 
auto listen (const unified::endpoint_info &bind_address, std::string_view id="") -> std::unique_ptr< unified::i_listener >
 Creates and starts a TCP listener in one call.
 
auto listen (uint16_t port, std::string_view id="") -> std::unique_ptr< unified::i_listener >
 Creates and starts a TCP listener on a specific port.
 

Function Documentation

◆ connect() [1/2]

auto kcenon::network::protocol::tcp::connect ( const unified::endpoint_info & endpoint,
std::string_view id = "" ) -> std::unique_ptr<unified::i_connection>
nodiscard

Creates and connects a TCP connection in one call.

Parameters
endpointThe remote endpoint to connect to
idOptional unique identifier for the connection
Returns
Unique pointer to an i_connection instance (connecting or connected)

This is a convenience function that creates a connection and immediately initiates the connection to the specified endpoint.

Usage Example

auto conn = protocol::tcp::connect({"localhost", 8080});
conn->set_callbacks({
.on_connected = []() { std::cout << "Connected!\n"; }
});
// Connection is already in progress
auto connect(const unified::endpoint_info &endpoint, std::string_view id="") -> std::unique_ptr< unified::i_connection >
Creates and connects a TCP connection in one call.
Definition tcp.cpp:39

Definition at line 39 of file tcp.cpp.

41{
42 auto conn = create_connection(id);
43 // Initiate connection (async, will complete in background)
44 (void)conn->connect(endpoint);
45 return conn;
46}

References create_connection().

Here is the call graph for this function:

◆ connect() [2/2]

auto kcenon::network::protocol::tcp::connect ( std::string_view url,
std::string_view id = "" ) -> std::unique_ptr<unified::i_connection>
nodiscard

Creates and connects a TCP connection using URL format.

Parameters
urlThe URL to connect to (format: "tcp://host:port" or "host:port")
idOptional unique identifier for the connection
Returns
Unique pointer to an i_connection instance (connecting or connected)

Definition at line 48 of file tcp.cpp.

50{
51 auto conn = create_connection(id);
52 (void)conn->connect(url);
53 return conn;
54}

References create_connection().

Here is the call graph for this function:

◆ create_connection()

auto kcenon::network::protocol::tcp::create_connection ( std::string_view id = "") -> std::unique_ptr<unified::i_connection>
nodiscard

Creates a TCP connection (not yet connected)

Parameters
idOptional unique identifier for the connection
Returns
Unique pointer to an i_connection instance

The returned connection is not connected. Call connect() to establish the connection to a remote endpoint.

Usage Example

auto conn = protocol::tcp::create_connection("my-client");
conn->set_callbacks({
.on_connected = []() { std::cout << "Connected!\n"; },
.on_data = [](std::span<const std::byte> data) { }
});
conn->connect({"localhost", 8080});
auto create_connection(std::string_view id="") -> std::unique_ptr< unified::i_connection >
Creates a TCP connection (not yet connected)
Definition tcp.cpp:33

Definition at line 33 of file tcp.cpp.

34{
35 std::string connection_id = id.empty() ? generate_unique_id("tcp-conn") : std::string(id);
36 return std::make_unique<unified::adapters::tcp_connection_adapter>(connection_id);
37}

Referenced by connect(), and connect().

Here is the caller graph for this function:

◆ create_listener()

auto kcenon::network::protocol::tcp::create_listener ( std::string_view id = "") -> std::unique_ptr<unified::i_listener>
nodiscard

Creates a TCP listener (not yet listening)

Parameters
idOptional unique identifier for the listener
Returns
Unique pointer to an i_listener instance

The returned listener is not listening. Call start() to begin accepting connections.

Usage Example

auto listener = protocol::tcp::create_listener("my-server");
listener->set_callbacks({
.on_accept = [](std::string_view conn_id) {
std::cout << "New connection: " << conn_id << "\n";
}
});
listener->start(8080);
auto create_listener(std::string_view id="") -> std::unique_ptr< unified::i_listener >
Creates a TCP listener (not yet listening)
Definition tcp.cpp:56

Definition at line 56 of file tcp.cpp.

57{
58 std::string listener_id = id.empty() ? generate_unique_id("tcp-listener") : std::string(id);
59 return std::make_unique<unified::adapters::tcp_listener_adapter>(listener_id);
60}

Referenced by listen().

Here is the caller graph for this function:

◆ listen() [1/2]

auto kcenon::network::protocol::tcp::listen ( const unified::endpoint_info & bind_address,
std::string_view id = "" ) -> std::unique_ptr<unified::i_listener>
nodiscard

Creates and starts a TCP listener in one call.

Parameters
bind_addressThe local address to bind to
idOptional unique identifier for the listener
Returns
Unique pointer to an i_listener instance (listening)

This is a convenience function that creates a listener and immediately starts listening on the specified address.

Usage Example

auto listener = protocol::tcp::listen({"0.0.0.0", 8080});
listener->set_callbacks({
.on_accept = [](std::string_view conn_id) { }
});
// Listener is already accepting connections
auto listen(const unified::endpoint_info &bind_address, std::string_view id="") -> std::unique_ptr< unified::i_listener >
Creates and starts a TCP listener in one call.
Definition tcp.cpp:62

Definition at line 62 of file tcp.cpp.

64{
65 auto listener = create_listener(id);
66 (void)listener->start(bind_address);
67 return listener;
68}

References create_listener().

Referenced by listen().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ listen() [2/2]

auto kcenon::network::protocol::tcp::listen ( uint16_t port,
std::string_view id = "" ) -> std::unique_ptr<unified::i_listener>
nodiscard

Creates and starts a TCP listener on a specific port.

Parameters
portThe port number to listen on
idOptional unique identifier for the listener
Returns
Unique pointer to an i_listener instance (listening)

Convenience overload that binds to all interfaces (0.0.0.0).

Definition at line 70 of file tcp.cpp.

71{
72 return listen(unified::endpoint_info{"0.0.0.0", port}, id);
73}
Network endpoint information (host/port or URL)
Definition types.h:56

References listen().

Here is the call graph for this function: