ASIO TCP connection switch
Hi, I have an application using ASIO TCP/IP SSL socket connection in an embedded device, the device has two network interfaces, when one is down, another network interface takes over, which requires application TCP SSL socket connection to be established binding to a new network interface. What will be an appropriate implementation to switch application TCP connection from one to another interface? Option 1: Restart application Option 2: Terminate the old interface socket, create a new socket to start initial connection Option 3: Some reconnection method which I don't know Appreciate you advice. Thank you. Kind regards, - jupiter
On 25/06/2019 17:43, JH wrote:
I have an application using ASIO TCP/IP SSL socket connection in an embedded device, the device has two network interfaces, when one is down, another network interface takes over, which requires application TCP SSL socket connection to be established binding to a new network interface. What will be an appropriate implementation to switch application TCP connection from one to another interface?
The simplest option is to not bind to a network interface in the first place. Provided that only at most one is up at a given moment, the OS will take care of routing the data appropriately. You're never allowed to have both interfaces up at the same time to the same network, unless the OS itself has special routing to handle failover -- in which case again, you don't need anything fancy in the application.
Hi Gavin,
I should clarify it is a client socket connection.
On 6/25/19, Gavin Lambert via Boost
On 25/06/2019 17:43, JH wrote:
I have an application using ASIO TCP/IP SSL socket connection in an embedded device, the device has two network interfaces, when one is down, another network interface takes over, which requires application TCP SSL socket connection to be established binding to a new network interface. What will be an appropriate implementation to switch application TCP connection from one to another interface?
The simplest option is to not bind to a network interface in the first place. Provided that only at most one is up at a given moment, the OS will take care of routing the data appropriately.
Did you mean to remove bind interface in client code, right? Sorry where I should to remove the bind to a network interface? Here is my client connection code: void AsyncClientSslConnection::InitialConnection(void) { boost::asio::ip::tcp::resolver::query query(this->mHost, this->mPort); boost::asio::ip::tcp::resolver::iterator iterator = this->mResolver.resolve(query); this->mSocket.set_verify_mode(boost::asio::ssl::verify_peer); this->mSocket.set_verify_callback(boost::bind(&AsyncClientSslConnection::VerifyCertificate, this, _1, _2)); boost::asio::async_connect(this->mSocket.lowest_layer(), iterator, boost::bind(&AsyncClientSslConnection::HandleConnect, this, boost::asio::placeholders::error)); } At the moment, when one interface is down, the client TCP socket keeps sending the data to server, but the remote server could no longer receive it.
You're never allowed to have both interfaces up at the same time to the same network, unless the OS itself has special routing to handle failover -- in which case again, you don't need anything fancy in the application.
You right, there would be only one interface has IP address, the OS is Linux Ubuntu and Yocto OS, I guess both should be able to handle failover, the key is where the binding statement? Thank you very much. - j
From other Internet discussions, it seems there is no way to switch an existing TCP socket connection from one interface to another,
Hi Gavin,
particularly, the NAT mapping is linked to 4-tuple, the only solution
is terminate the connection by deleting the socket, then create a new
socket and connection again. If you have different view could you
please elaborate how Linux OS
can take care of routing the data appropriately?
Thank you very much.
Kind regards,
- jupiter
On 6/25/19, JH
Hi Gavin,
I should clarify it is a client socket connection.
On 6/25/19, Gavin Lambert via Boost
wrote: On 25/06/2019 17:43, JH wrote:
I have an application using ASIO TCP/IP SSL socket connection in an embedded device, the device has two network interfaces, when one is down, another network interface takes over, which requires application TCP SSL socket connection to be established binding to a new network interface. What will be an appropriate implementation to switch application TCP connection from one to another interface?
The simplest option is to not bind to a network interface in the first place. Provided that only at most one is up at a given moment, the OS will take care of routing the data appropriately.
Did you mean to remove bind interface in client code, right? Sorry where I should to remove the bind to a network interface? Here is my client connection code:
void AsyncClientSslConnection::InitialConnection(void) { boost::asio::ip::tcp::resolver::query query(this->mHost, this->mPort); boost::asio::ip::tcp::resolver::iterator iterator = this->mResolver.resolve(query); this->mSocket.set_verify_mode(boost::asio::ssl::verify_peer);
this->mSocket.set_verify_callback(boost::bind(&AsyncClientSslConnection::VerifyCertificate, this, _1, _2)); boost::asio::async_connect(this->mSocket.lowest_layer(), iterator, boost::bind(&AsyncClientSslConnection::HandleConnect, this, boost::asio::placeholders::error)); }
At the moment, when one interface is down, the client TCP socket keeps sending the data to server, but the remote server could no longer receive it.
You're never allowed to have both interfaces up at the same time to the same network, unless the OS itself has special routing to handle failover -- in which case again, you don't need anything fancy in the application.
You right, there would be only one interface has IP address, the OS is Linux Ubuntu and Yocto OS, I guess both should be able to handle failover, the key is where the binding statement?
Thank you very much.
- j
On 6/25/19 8:43 AM, JH via Boost wrote:
Hi,
I have an application using ASIO TCP/IP SSL socket connection in an embedded device, the device has two network interfaces, when one is down, another network interface takes over, which requires application TCP SSL socket connection to be established binding to a new network interface. What will be an appropriate implementation to switch application TCP connection from one to another interface?
Option 1: Restart application
Option 2: Terminate the old interface socket, create a new socket to start initial connection
Option 3: Some reconnection method which I don't know
With plain TCP and two distinct network interfaces, I don't think there is a way except to re-establish TCP/TLS connection when you detect that the previous connection died. Which you should detect as soon as you try sending something. This is the reason why most of the time you need some sort of periodic keepalive exchange with the server. Other than that, you may look into more advanced network configurations, like interface bonding, for example. Your application will open the connection on the bond interface and then the OS will decide which lower level interface to use to send data. I haven't done that, but as I understand it, it should work more or less transparently to your application.
participants (3)
-
Andrey Semashev
-
Gavin Lambert
-
JH