Connecting to Devices#
Before interacting with OCA objects, the controller must establish a network connection to the device. libaes70 provides integration points for different networking libraries, so you can choose the one that fits your project.
Creating controller connections is currently only implemented for the libuv integration. If you need controller support for other platforms, e.g. using lwIP for embedded platforms or boost::asio reach out to us.
An example for establishing a connection can be found in the example in examples/simple_controller
:
static void connect()
{
std::cerr << "Trying to connect to device." << std::endl;
libuv::tcp::connect<aes70::controller::connection>("127.0.0.1", 65123,
[&](const char *error,
std::shared_ptr<aes70::controller::connection> con) {
if (!error)
{
std::cerr << "connected." << std::endl;
con->set_keepalive_interval(1000);
connected(con);
subs.add(con->onclose(
[](const aes70::controller::connection &) { closed(); }));
}
else
{
std::cerr << "connection failed: " << error << std::endl;
closed();
}
});
}
int main(int argc, const char **argv)
{
connect();
return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}
Note
It is generally recommended to use set_keepalive_interval
to enable keepalive
messages. Otherwise the detection of connection loss can be unreliable.
Detecting connection loss#
For long-running applications which must handle the loss of connections, the onclose()
method
must be used to handle connection loss events. The recommended approach is to then re-create
a connection after some time interval.
Note
Note that the subscription
returned from onclose()
must be kept alive until the connection
is lost. See aes70::controller::subscription
for details.