NetworkAvailabilityChanged Cerbuino issues

Hello guys,
It seems that the NetworkAvailabilityChanged is not triggered when the board starts with a cable attached… to me it should trigger and report True, when the board starts with the network cable attached to a router… right now we have no way to detecting the network is up reliably…

here is a test code.

    void ProgramStarted()
             NetworkChange.NetworkAvailabilityChanged += NetworkChange_NetworkAvailabilityChanged;
             Interfaces = NetworkInterface.GetAllNetworkInterfaces();

             _networkInterface = Interfaces[0];
             if (_networkInterface.IsDhcpEnabled == false) _networkInterface.EnableDhcp();
        void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
            Debug.Print("Network Availability Changed: " + e.IsAvailable);

as it stands now, the code has no way of knowing the state of the Net Cable when it starts…

another issue I noticed is when I bind to a UDP port I unplug the cable, close the socket, free it… reconnect the cable try to bind to the same IP and Port I get an exception, if I change the Cable to a different Port on the Router it works as expected, and NO the IP Address is always the same :slight_smile: and hasn’t changed… why?

Oh yah the NetworkAddressChanged is unreliable as it kicks in once in a moon, where it should kick in when the cable is plugged and a new IPAddress is assigned, remind you that the board starts with no IPAddress…so it must trigger as well… and when the cable is unplugged it should kick in again with NO IPAddress… and so on…

 NetworkChange.NetworkAddressChanged += NetworkChange_NetworkAddressChanged;

I hope you guys run few tests when you work on the networking stack…

We will look into it but can be worked around by pinging a server so it is a lower priority for now.

Actually it Won’t work…

because when you loose the Network due to cable being unplugged, any pending UDP SEND and TCP Listen will cause exceptions and unexpected behavior will happen causing a system to crash…

any ideas on how to work around those situations?

Catch the exceptions and not let the system crash, perhaps?

tried that, but it’s unpredictable what the exception might be… and once it’s broken the underlying socket become broken and useless freezes the system sometimes… even releasing the socket and trying to rebind again doesn’t work (another weird issue) unless I plug cable onto another port of the router… while still using the same IP and Port… go figure why…

anyway the only reliable way of doing this right is hooking into the events… and shutting things down the clean way…

@ andre.m -

I appreciate all the help but again that won’t work… try it and you’ll see what I mean…

the Code holds on to the IPAddress even when the cable is unplugged :frowning: