|
Boost : |
From: Gavin Lambert (boost_at_[hidden])
Date: 2019-07-03 01:22:22
On 29/06/2019 12:35, JH wrote:
> 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.
Receiving on a broken socket reports no errors. Trying to send on a
broken socket, however, should normally return an error code. Are you
sure you're checking in the right places?
> 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:
[...]
> 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?
Transition from one interface to another is not immediate. Whatever is
handling the transition has to first notice that the original interface
failed (typically with some timeout) and then perform the transition,
which itself might take a while. (Ethernet link negotiation takes ~2
seconds typically for example, although that might not be a factor here
depending on exactly what is happening.)
When a connection fails, you need to keep retrying until it succeeds --
usually with a second or two delay between each retry (or exponential
backoff) to avoid flooding the system with connection retry requests.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk