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

Nanomsg client. More...

#include <client.h>

Inheritance diagram for CppServer::Nanomsg::Client:
CppServer::Nanomsg::PairClient CppServer::Nanomsg::PushClient CppServer::Nanomsg::RequestClient CppServer::Nanomsg::SubscribeClient CppServer::Nanomsg::SurveyClient

Public Member Functions

 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...
 

Protected Member Functions

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 client.

Nanomsg client is used to send messages to the Nanomsg server and receive responses back.

Thread-safe.

Definition at line 29 of file client.h.

Constructor & Destructor Documentation

◆ Client() [1/3]

CppServer::Nanomsg::Client::Client ( Domain  domain,
Protocol  protocol,
const std::string &  address,
bool  threading = true 
)
explicit

Initialize client with a given domain, protocol and endpoint address.

Parameters
domain- Domain
protocol- Protocol
address- Endpoint address
threading- Run the client in a separate thread (default is true)

Definition at line 19 of file client.cpp.

◆ Client() [2/3]

CppServer::Nanomsg::Client::Client ( const Client )
delete

◆ Client() [3/3]

CppServer::Nanomsg::Client::Client ( Client &&  )
default

◆ ~Client()

CppServer::Nanomsg::Client::~Client ( )
virtual

Definition at line 32 of file client.cpp.

Member Function Documentation

◆ Connect()

bool CppServer::Nanomsg::Client::Connect ( )

Connect the client.

Returns
'true' if the client was successfully connected, 'false' if the client failed to connect
Examples:
nanomsg_pair_client.cpp, nanomsg_push_client.cpp, nanomsg_request_client.cpp, nanomsg_subscribe_client.cpp, and nanomsg_survey_client.cpp.

Definition at line 46 of file client.cpp.

◆ Disconnect()

bool CppServer::Nanomsg::Client::Disconnect ( )

Disconnect the client.

Returns
'true' if the client was successfully disconnected, 'false' if the client is already disconnected

Definition at line 73 of file client.cpp.

◆ IsConnected()

bool CppServer::Nanomsg::Client::IsConnected ( ) const
inlinenoexcept

Is the client connected?

Definition at line 51 of file client.h.

◆ onConnected()

virtual void CppServer::Nanomsg::Client::onConnected ( )
inlineprotectedvirtual

Handle client connected notification.

Examples:
nanomsg_pair_client.cpp, nanomsg_push_client.cpp, nanomsg_request_client.cpp, nanomsg_subscribe_client.cpp, and nanomsg_survey_client.cpp.

Definition at line 136 of file client.h.

◆ onDisconnected()

virtual void CppServer::Nanomsg::Client::onDisconnected ( )
inlineprotectedvirtual

Handle client disconnected notification.

Examples:
nanomsg_pair_client.cpp, nanomsg_push_client.cpp, nanomsg_request_client.cpp, nanomsg_subscribe_client.cpp, and nanomsg_survey_client.cpp.

Definition at line 138 of file client.h.

◆ onError()

virtual void CppServer::Nanomsg::Client::onError ( int  error,
const std::string &  message 
)
inlineprotectedvirtual

Handle error notification.

Parameters
error- Error code
message- Error message
Examples:
nanomsg_pair_client.cpp, nanomsg_push_client.cpp, nanomsg_request_client.cpp, nanomsg_subscribe_client.cpp, and nanomsg_survey_client.cpp.

Definition at line 154 of file client.h.

◆ onIdle()

virtual void CppServer::Nanomsg::Client::onIdle ( )
inlineprotectedvirtual

Handle client idle notification.

Definition at line 141 of file client.h.

◆ onReceived()

virtual void CppServer::Nanomsg::Client::onReceived ( Message message)
inlineprotectedvirtual

Handle message received notification.

Parameters
message- Received message
Examples:
nanomsg_pair_client.cpp, nanomsg_subscribe_client.cpp, and nanomsg_survey_client.cpp.

Definition at line 147 of file client.h.

◆ onThreadCleanup()

virtual void CppServer::Nanomsg::Client::onThreadCleanup ( )
inlineprotectedvirtual

Cleanup thread handler.

This handler can be used to cleanup priority or affinity of the client thread.

Definition at line 133 of file client.h.

◆ onThreadInitialize()

virtual void CppServer::Nanomsg::Client::onThreadInitialize ( )
inlineprotectedvirtual

Initialize thread handler.

This handler can be used to initialize priority or affinity of the client thread.

Definition at line 128 of file client.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Receive()

size_t CppServer::Nanomsg::Client::Receive ( Message message)

Receive a message from the server.

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 189 of file client.cpp.

◆ Reconnect()

bool CppServer::Nanomsg::Client::Reconnect ( )

Reconnect the client.

Returns
'true' if the client was successfully reconnected, 'false' if the client failed to reconnect

Definition at line 100 of file client.cpp.

◆ Send() [1/3]

size_t CppServer::Nanomsg::Client::Send ( const void *  buffer,
size_t  size 
)

Send data to the server.

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Count of sent bytes
Examples:
nanomsg_survey_client.cpp.

Definition at line 157 of file client.cpp.

◆ Send() [2/3]

size_t CppServer::Nanomsg::Client::Send ( const std::string &  text)
inline

Send a text string to the server.

Parameters
text- Text string to send
Returns
Count of sent bytes

Definition at line 81 of file client.h.

◆ Send() [3/3]

size_t CppServer::Nanomsg::Client::Send ( const Message message)
inline

Send a message to the server.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 87 of file client.h.

◆ socket()

Socket& CppServer::Nanomsg::Client::socket ( )
inlinenoexcept

Get the Nanomsg socket.

Definition at line 48 of file client.h.

◆ TryReceive()

size_t CppServer::Nanomsg::Client::TryReceive ( Message message)

Try to receive a message from the server in non-blocking mode.

Parameters
message- Message to receive
Returns
Count of received bytes

Definition at line 211 of file client.cpp.

◆ TrySend() [1/3]

size_t CppServer::Nanomsg::Client::TrySend ( const void *  buffer,
size_t  size 
)

Try to send data to the server in non-blocking mode.

Parameters
buffer- Buffer to send
size- Buffer size
Returns
Count of sent bytes

Definition at line 173 of file client.cpp.

◆ TrySend() [2/3]

size_t CppServer::Nanomsg::Client::TrySend ( const std::string &  text)
inline

Try to send a text string to the server in non-blocking mode.

Parameters
text- Text string to send
Returns
Count of sent bytes

Definition at line 101 of file client.h.

◆ TrySend() [3/3]

size_t CppServer::Nanomsg::Client::TrySend ( const Message message)
inline

Try to send a message to the server in non-blocking mode.

Parameters
message- Message to send
Returns
Count of sent bytes

Definition at line 107 of file client.h.


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