9 #ifndef CPPSERVER_NANOMSG_CLIENT_H 10 #define CPPSERVER_NANOMSG_CLIENT_H 14 #include "threads/thread.h" 39 explicit Client(
Domain domain,
Protocol protocol,
const std::string& address,
bool threading =
true);
75 size_t Send(
const void* buffer,
size_t size);
81 size_t Send(
const std::string& text) {
return Send(text.data(), text.size()); }
95 size_t TrySend(
const void* buffer,
size_t size);
101 size_t TrySend(
const std::string& text) {
return TrySend(text.data(), text.size()); }
141 virtual void onIdle() { CppCommon::Thread::Yield(); }
154 virtual void onError(
int error,
const std::string& message) {}
158 std::string _address;
161 std::atomic<bool> _connected;
165 std::atomic<bool> _joining;
166 std::atomic<bool> _receiving;
175 #endif // CPPSERVER_NANOMSG_CLIENT_H size_t Send(const std::string &text)
Send a text string to the server.
virtual void onDisconnected()
Handle client disconnected notification.
size_t Receive(Message &message)
Receive a message from the server.
virtual void onError(int error, const std::string &message)
Handle error notification.
size_t Send(const Message &message)
Send a message to the server.
size_t size() const noexcept
Get the message size.
bool Reconnect()
Reconnect the client.
C++ Server project definitions.
bool Disconnect()
Disconnect the client.
virtual void onConnected()
Handle client connected notification.
virtual void onIdle()
Handle client idle notification.
bool IsConnected() const noexcept
Is the client connected?
size_t Send(const void *buffer, size_t size)
Send data to the server.
size_t TrySend(const void *buffer, size_t size)
Try to send data to the server in non-blocking mode.
size_t TrySend(const std::string &text)
Try to send a text string to the server in non-blocking mode.
size_t TryReceive(Message &message)
Try to receive a message from the server in non-blocking mode.
uint8_t * buffer() noexcept
Get the message buffer.
bool IsConnected() const noexcept
Is socket connected?
Client(Domain domain, Protocol protocol, const std::string &address, bool threading=true)
Initialize client with a given domain, protocol and endpoint address.
Client & operator=(const Client &)=delete
Protocol
Nanomsg protocol.
bool Connect()
Connect the client.
size_t TrySend(const Message &message)
Try to send a message to the server in non-blocking mode.
virtual void onReceived(Message &message)
Handle message received notification.
virtual void onThreadInitialize()
Initialize thread handler.
Nanomsg socket definition.
bool IsOpened() const noexcept
Is socket opened?
virtual void onThreadCleanup()
Cleanup thread handler.
Socket & socket() noexcept
Get the Nanomsg socket.