CppWAMP
C++11 client library for the WAMP protocol
|
wamp::Connector is the abstract base class for objects that can establish client transport endpoints.
The library currently supports two types of connectors:
Connector Factory | Declared in | For Transport |
---|---|---|
connector<TCodec>(AnyExecutor, TcpHost) | <cppwamp/tcp.hpp> | TCP raw socket |
connector<TCodec>(AnyExecutor, UdsPath) | <cppwamp/uds.hpp> | Unix domain socket |
When creating a connector, you must specify which codec class (aka serializer) to use for encoding WAMP messages. The following codecs are currently supported:
Codec | Declared in |
---|---|
wamp::Json | <cppwamp/json.hpp> |
wamp::Msgpack | <cppwamp/msgpack.hpp> |
wamp::Cbor | <cppwamp/cbor.hpp> |
Connectors are created on the heap using the wamp::connector
factory function as shown in the examples below. wamp::connector
returns a std::shared_ptr
to the newly created wamp::Connector.
After you have created one or more connectors, you pass them to the session API. The session object will then use these connectors while establishing a transport connection to the router.
The wamp::TcpHost object allows you to specify extra socket options. See the reference documentation for more details.
Likewise, the wamp::UdsPath object also allows you to specify extra socket options.
This snippet below shows how to create a TCP connector with a specified maximum incoming message length, as well as with Nagle's algorithm disabled:
More than one Connector
can be passed to a session object. In such cases, the session will successively attempt to establish a transport connection with each of the connectors until one succeeds. This allows you to specify "fallback" transports if the primary one fails to establish.
To achieve this, you must pass a std::vector
of Connector
shared pointers while creating session objects. The following example uses two TcpConnector
objects, each specifying a different serializer:
Next: Sessions