CppServer  1.0.0.0
C++ Server Library
Public Member Functions | List of all members
CppServer::Nanomsg::RequestClient Class Reference

Nanomsg request client. More...

#include <request_client.h>

Inheritance diagram for CppServer::Nanomsg::RequestClient:
CppServer::Nanomsg::Client

Public Member Functions

 RequestClient (const std::string &address, bool threading=false)
 Initialize client with a given endpoint address. More...
 
 RequestClient (const RequestClient &)=delete
 
 RequestClient (RequestClient &&)=default
 
virtual ~RequestClient ()=default
 
RequestClientoperator= (const RequestClient &)=delete
 
RequestClientoperator= (RequestClient &&)=default
 
Message Request (const void *buffer, size_t size)
 Request data to the server. More...
 
Message Request (const std::string &text)
 Request a text string to the server. More...
 
Message Request (const Message &message)
 Request a message to the server. More...
 
- Public Member Functions inherited from CppServer::Nanomsg::Client
 Client (Domain domain, Protocol protocol, const std::string &address, bool threading=true)
 Initialize client with a given domain, protocol and endpoint address. More...
 
 Client (const Client &)=delete
 
 Client (Client &&)=default
 
virtual ~Client ()
 
Clientoperator= (const Client &)=delete
 
Clientoperator= (Client &&)=default
 
Socketsocket () noexcept
 Get the Nanomsg socket. More...
 
bool IsConnected () const noexcept
 Is the client connected? More...
 
bool Connect ()
 Connect the client. More...
 
bool Disconnect ()
 Disconnect the client. More...
 
bool Reconnect ()
 Reconnect the client. More...
 
size_t Send (const void *buffer, size_t size)
 Send data to the server. More...
 
size_t Send (const std::string &text)
 Send a text string to the server. More...
 
size_t Send (const Message &message)
 Send a message to the server. More...
 
size_t TrySend (const void *buffer, size_t size)
 Try to send data to the server in non-blocking mode. More...
 
size_t TrySend (const std::string &text)
 Try to send a text string to the server in non-blocking mode. More...
 
size_t TrySend (const Message &message)
 Try to send a message to the server in non-blocking mode. More...
 
size_t Receive (Message &message)
 Receive a message from the server. More...
 
size_t TryReceive (Message &message)
 Try to receive a message from the server in non-blocking mode. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CppServer::Nanomsg::Client
virtual void onThreadInitialize ()
 Initialize thread handler. More...
 
virtual void onThreadCleanup ()
 Cleanup thread handler. More...
 
virtual void onConnected ()
 Handle client connected notification. More...
 
virtual void onDisconnected ()
 Handle client disconnected notification. More...
 
virtual void onIdle ()
 Handle client idle notification. More...
 
virtual void onReceived (Message &message)
 Handle message received notification. More...
 
virtual void onError (int error, const std::string &message)
 Handle error notification. More...
 

Detailed Description

Nanomsg request client.

Nanomsg request client is used to send requests to the Nanomsg reply server and receive corresponding responses from it.

This protocol is used to distribute the workload among multiple stateless workers.

Please note that request/reply applications should be stateless.

It's important to include all the information necessary to process the request in the request itself, including information about the sender or the originator of the request if this is necessary to respond to the request.

Sender information cannot be retrieved from the underlying socket connection since, firstly, transports like IPC may not have a firm notion of a message origin. Secondly, transports that have some notion may not have a reliable one

For this reason, sender information must be included by the application if required. Allocating 6 randomly-generated bytes in the message for the lifetime of the connection is sufficient for most purposes. For longer-lived applications, an UUID is more suitable.

Thread-safe.

Examples:
nanomsg_request_client.cpp.

Definition at line 44 of file request_client.h.

Constructor & Destructor Documentation

◆ RequestClient() [1/3]

CppServer::Nanomsg::RequestClient::RequestClient ( const std::string &  address,
bool  threading = false 
)
inlineexplicit

Initialize client with a given endpoint address.

Parameters
address- Endpoint address
threading- Run the client in a separate thread (default is false)
Examples:
nanomsg_request_client.cpp.

Definition at line 52 of file request_client.h.

◆ RequestClient() [2/3]

CppServer::Nanomsg::RequestClient::RequestClient ( const RequestClient )
delete

◆ RequestClient() [3/3]

CppServer::Nanomsg::RequestClient::RequestClient ( RequestClient &&  )
default

◆ ~RequestClient()

virtual CppServer::Nanomsg::RequestClient::~RequestClient ( )
virtualdefault

Member Function Documentation

◆ operator=() [1/2]

RequestClient& CppServer::Nanomsg::RequestClient::operator= ( const RequestClient )
delete

◆ operator=() [2/2]

RequestClient& CppServer::Nanomsg::RequestClient::operator= ( RequestClient &&  )
default

◆ Request() [1/3]

Message CppServer::Nanomsg::RequestClient::Request ( const void *  buffer,
size_t  size 
)
inline

Request data to the server.

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Reply message

Definition at line 68 of file request_client.h.

◆ Request() [2/3]

Message CppServer::Nanomsg::RequestClient::Request ( const std::string &  text)
inline

Request a text string to the server.

Parameters
text- Text string to send
Returns
Reply message

Definition at line 80 of file request_client.h.

◆ Request() [3/3]

Message CppServer::Nanomsg::RequestClient::Request ( const Message message)
inline

Request a message to the server.

Parameters
message- Message to send
Returns
Reply message

Definition at line 86 of file request_client.h.


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