Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
ModernClient Class Reference

Modern client using new API. More...

Collaboration diagram for ModernClient:
Collaboration graph

Public Member Functions

 ModernClient (const std::string &id)
 
bool connect (const std::string &host, uint16_t port)
 
size_t send_batch (const std::vector< std::string > &messages)
 
void send_async (const std::string &message)
 
bool disconnect ()
 

Private Attributes

std::string client_id_
 
std::shared_ptr< core::messaging_client > client_
 

Detailed Description

Modern client using new API.

Definition at line 145 of file modern_usage.cpp.

Constructor & Destructor Documentation

◆ ModernClient()

ModernClient::ModernClient ( const std::string & id)
inline

Definition at line 147 of file modern_usage.cpp.

147 : client_id_(id) {
148 client_ = std::make_shared<core::messaging_client>(client_id_);
149 std::cout << "[Modern Client] Created with ID: " << client_id_ << std::endl;
150 }
std::string client_id_
std::shared_ptr< core::messaging_client > client_

References client_, and client_id_.

Member Function Documentation

◆ connect()

bool ModernClient::connect ( const std::string & host,
uint16_t port )
inline

Definition at line 152 of file modern_usage.cpp.

152 {
153 auto result = client_->start_client(host, port);
154 if (result.is_err()) {
155 std::cerr << "[Modern Client] Failed to connect: " << result.error().message
156 << " (code: " << result.error().code << ")" << std::endl;
157 return false;
158 }
159
160 std::cout << "[Modern Client] Connecting to " << host << ":" << port << std::endl;
161 std::this_thread::sleep_for(200ms); // Give time to connect
162 return true;
163 }
auto start_client(std::string_view host, unsigned short port) -> VoidResult
Starts the client and connects to the specified host and port.

References client_, and kcenon::network::core::messaging_client::start_client().

Here is the call graph for this function:

◆ disconnect()

bool ModernClient::disconnect ( )
inline

Definition at line 204 of file modern_usage.cpp.

204 {
205 auto result = client_->stop_client();
206 if (result.is_err()) {
207 std::cerr << "[Modern Client] Failed to disconnect: " << result.error().message
208 << " (code: " << result.error().code << ")" << std::endl;
209 return false;
210 }
211
212 std::cout << "[Modern Client] Disconnected" << std::endl;
213 return true;
214 }
auto stop_client() -> VoidResult
Stops the client and disconnects from the server.

References client_, and kcenon::network::core::messaging_client::stop_client().

Here is the call graph for this function:

◆ send_async()

void ModernClient::send_async ( const std::string & message)
inline

Definition at line 189 of file modern_usage.cpp.

189 {
191 thread_mgr.submit_task([this, message]() {
192 std::vector<uint8_t> data(message.begin(), message.end());
193 auto result = client_->send_packet(data);
194
195 if (result.is_err()) {
196 std::cerr << "[Modern Client] Async send failed: " << result.error().message
197 << " (code: " << result.error().code << ")" << std::endl;
198 } else {
199 std::cout << "[Modern Client] Async sent: " << message << std::endl;
200 }
201 });
202 }
auto send_packet(std::vector< uint8_t > &&data) -> VoidResult
Sends data to the connected server.
static thread_integration_manager & instance()
Get the singleton instance.

References client_, kcenon::network::integration::thread_integration_manager::instance(), kcenon::network::message, and kcenon::network::core::messaging_client::send_packet().

Here is the call graph for this function:

◆ send_batch()

size_t ModernClient::send_batch ( const std::vector< std::string > & messages)
inline

Definition at line 165 of file modern_usage.cpp.

165 {
166 std::cout << "[Modern Client] Sending batch of " << messages.size()
167 << " messages" << std::endl;
168
169 size_t successful = 0;
170 for (const auto& msg : messages) {
171 std::vector<uint8_t> data(msg.begin(), msg.end());
172 auto result = client_->send_packet(data);
173
174 if (result.is_err()) {
175 std::cerr << "[Modern Client] Failed to send message: " << result.error().message
176 << " (code: " << result.error().code << ")" << std::endl;
177 } else {
178 successful++;
179 }
180
181 std::this_thread::sleep_for(50ms);
182 }
183
184 std::cout << "[Modern Client] Successfully sent " << successful << "/" << messages.size()
185 << " messages" << std::endl;
186 return successful;
187 }

References client_, and kcenon::network::core::messaging_client::send_packet().

Here is the call graph for this function:

Member Data Documentation

◆ client_

std::shared_ptr<core::messaging_client> ModernClient::client_
private

Definition at line 218 of file modern_usage.cpp.

Referenced by connect(), disconnect(), ModernClient(), send_async(), and send_batch().

◆ client_id_

std::string ModernClient::client_id_
private

Definition at line 217 of file modern_usage.cpp.

Referenced by ModernClient().


The documentation for this class was generated from the following file: