CppServer  1.0.0.0
C++ Server Library
subscribe_client.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERVER_NANOMSG_SUBSCRIBE_CLIENT_H
10 #define CPPSERVER_NANOMSG_SUBSCRIBE_CLIENT_H
11 
12 #include "client.h"
13 
14 namespace CppServer {
15 namespace Nanomsg {
16 
18 
29 class SubscribeClient : public Client
30 {
31 public:
33 
38  explicit SubscribeClient(const std::string& address, const std::string& topic = "", bool threading = true)
39  : Client(CppServer::Nanomsg::Domain::Std, CppServer::Nanomsg::Protocol::Subscriber, address, threading)
40  {
41  socket().SetSocketOption(NN_SUB, NN_SUB_SUBSCRIBE, topic.data(), topic.size());
42  }
43  SubscribeClient(const SubscribeClient&) = delete;
44  SubscribeClient(SubscribeClient&&) = default;
45  virtual ~SubscribeClient() = default;
46 
47  SubscribeClient& operator=(const SubscribeClient&) = delete;
49 
50 private:
51  using Client::Send;
52  using Client::TrySend;
53 };
54 
57 } // namespace Nanomsg
58 } // namespace CppServer
59 
60 #endif // CPPSERVER_NANOMSG_SUBSCRIBE_CLIENT_H
Receives messages from the publisher. Send operation is not defined.
bool SetSocketOption(int level, int option, const void *value, size_t size)
Set the socket option.
Definition: socket.cpp:136
C++ Server project definitions.
Definition: asio.h:24
size_t Send(const void *buffer, size_t size)
Send data to the server.
Definition: client.cpp:157
Nanomsg subscribe client.
size_t TrySend(const void *buffer, size_t size)
Try to send data to the server in non-blocking mode.
Definition: client.cpp:173
SubscribeClient & operator=(const SubscribeClient &)=delete
Protocol
Nanomsg protocol.
Definition: nanomsg.h:56
SubscribeClient(const std::string &address, const std::string &topic="", bool threading=true)
Initialize client with a given endpoint address.
Nanomsg client.
Definition: client.h:29
Domain
Nanomsg domain.
Definition: nanomsg.h:41
Nanomsg client definition.
Standard full-blown socket.
Socket & socket() noexcept
Get the Nanomsg socket.
Definition: client.h:48