CppServer
1.0.0.0
C++ Server Library
|
Nanomsg request client. More...
#include <request_client.h>
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 |
RequestClient & | operator= (const RequestClient &)=delete |
RequestClient & | operator= (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... | |
![]() | |
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 () |
Client & | operator= (const Client &)=delete |
Client & | operator= (Client &&)=default |
Socket & | socket () 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 | |
![]() | |
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... | |
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.
Definition at line 44 of file request_client.h.
|
inlineexplicit |
Initialize client with a given endpoint address.
address | - Endpoint address |
threading | - Run the client in a separate thread (default is false) |
Definition at line 52 of file request_client.h.
|
delete |
|
default |
|
virtualdefault |
|
delete |
|
default |
|
inline |
Request data to the server.
buffer | - Buffer to send |
size | - Buffer size |
Definition at line 68 of file request_client.h.
|
inline |
Request a text string to the server.
text | - Text string to send |
Definition at line 80 of file request_client.h.
Request a message to the server.
message | - Message to send |
Definition at line 86 of file request_client.h.