|
Boost : |
From: JH (jupiter.hce_at_[hidden])
Date: 2019-06-29 00:35:24
Sorry for keeping posting questions about ASIO TCP socket reconnection
regarding to network interface changes, I am very much stuck at the
moment.
As I described in other emails, when one network interface WiFi
failed, the network interface Ethernet takes over, the client
application using boost ASIO TCP socket cannot detect the broken of
WiFi, it continually sent messages to the remote server via the broken
WiFi interface without triggering errors but obviously the server
could not receive messages any more.
So my solution is prior to send message, it ping to 8.8.8.8 via the
network interface WiFi, if it failed, it called the SetConnection
again to close the socket binding to WiFi interface and to start
reconnection to bind to Ethernet interface:
void SetConnection(void) {
if (this->mSocket.lowest_layer().is_open()) {
std::cout << "Set connection close socket" << std::endl;
this->mSocket.lowest_layer().close();
}
boost::asio::ip::tcp::resolver resolver(this->mIoService);
boost::asio::ip::tcp::resolver::query query(this->mHost, this->mPort);
this->mIterator = resolver.resolve(query);
this->mContext.load_verify_file("ssl/ca.pem");
this->mSocket.set_verify_mode(boost::asio::ssl::verify_peer);
this->mSocket.set_verify_callback(boost::bind(&client::verify_certificate,
this, _1, _2));
boost::asio::async_connect(mSocket.lowest_layer(),
this->mIterator, boost::bind(&client::handle_connect, this,
boost::asio::placeholders::error));
}
But it did not work, the error: handle_connect connect failed: Network
is unreachable
What I am missing here? How can I make the TCP socket reconnection?
Thank you.
Kind regards,
- jupiter
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk