CppServer
1.0.0.0
C++ Server Library
|
Nanomsg request server. More...
#include <request_server.h>
Public Member Functions | |
RequestServer (const std::string &address, bool threading=true) | |
Initialize server with a given endpoint address. More... | |
RequestServer (const RequestServer &)=delete | |
RequestServer (RequestServer &&)=default | |
virtual | ~RequestServer ()=default |
RequestServer & | operator= (const RequestServer &)=delete |
RequestServer & | operator= (RequestServer &&)=default |
![]() | |
Server (Domain domain, Protocol protocol, const std::string &address, bool threading=true) | |
Initialize server with a given domain, protocol and endpoint address. More... | |
Server (const Server &)=delete | |
Server (Server &&)=default | |
virtual | ~Server () |
Server & | operator= (const Server &)=delete |
Server & | operator= (Server &&)=default |
Socket & | socket () noexcept |
Get the Nanomsg socket. More... | |
bool | IsStarted () const noexcept |
Is the server started? More... | |
bool | Start () |
Start the server. More... | |
bool | Stop () |
Stop the server. More... | |
bool | Restart () |
Restart the server. More... | |
size_t | Send (const void *buffer, size_t size) |
Send data to the client. More... | |
size_t | Send (const std::string &text) |
Send a text string to the client. More... | |
size_t | Send (const Message &message) |
Send a message to the client. More... | |
size_t | TrySend (const void *buffer, size_t size) |
Try to send data to the client in non-blocking mode. More... | |
size_t | TrySend (const std::string &text) |
Try to send a text string to the client in non-blocking mode. More... | |
size_t | TrySend (const Message &message) |
Try to send a message to the client in non-blocking mode. More... | |
size_t | Receive (Message &message) |
Receive a message from the client. More... | |
size_t | TryReceive (Message &message) |
Try to receive a message from the client in non-blocking mode. More... | |
Additional Inherited Members | |
![]() | |
virtual void | onThreadInitialize () |
Initialize thread handler. More... | |
virtual void | onThreadCleanup () |
Cleanup thread handler. More... | |
virtual void | onStarted () |
Handle server started notification. More... | |
virtual void | onStopped () |
Handle server stopped notification. More... | |
virtual void | onIdle () |
Handle server 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 server.
Nanomsg request server is used to receive requests from Nanomsg clients and reply with corresponding responses.
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_server.h.
|
inlineexplicit |
Initialize server with a given endpoint address.
address | - Endpoint address |
threading | - Run the server in a separate thread (default is true) |
Definition at line 52 of file request_server.h.
|
delete |
|
default |
|
virtualdefault |
|
delete |
|
default |