aricpp::Client websocket - what if the connection breaks? #31
-
The aricpp::Client constructor creates a Websocket connection to get events from the Asterisk server. This is meant to be a long term connection to the server; however, in production environments the websocket can get disconnected. From that point on, no messages will be received from Asterisk. I was looking at questions like this one on stackoverflow but I don't see a way to do that here. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Have you tried doing again a |
Beta Was this translation helpful? Give feedback.
-
The following code works for me when my ARI must wait to connect to Asterisk. function<void()> RetryConnect=[&]()
{
pcClient->Connect([&](sys::error_code cError)
{
if (cError)
{
g_cLog.LogError("ARI client connect error (%d: %s)", cError.value(), cError.message().c_str());
if ((cError.value() == sys::errc::connection_refused) // "Connection refused"
|| (cError.value() == sys::errc::not_a_directory)) // "The WebSocket handshake was declined by the remote peer"
{
pcClient->Close();
cTimer.expires_after(chrono::seconds(10));
cTimer.async_wait([&](boost::system::error_code cError)
{
if (cError)
{
g_cLog.LogError("ARI client wait error (%d: %s)", cError.value(), cError.message().c_str());
pcIOService->stop();
}
else
{
g_cLog.LogInfo("ARI client reconnecting to Asterisk");
RetryConnect();
}
});
}
else
{
pcIOService->stop();
}
}
else
{
g_cLog.LogInfo("ARI client connected to Asterisk");
}
});
};
RetryConnect(); |
Beta Was this translation helpful? Give feedback.
-
I just committed a solution: |
Beta Was this translation helpful? Give feedback.
I just committed a solution:
e3c4fa8
Now there is an optional parameter on
Client::Connect
that specifies the reconnection period in seconds.Please, can you try it and give me feedback?
Thanks