Main Site Documentation

When reconnecting network cable takes a while before network is actually up - ho can it be detected when is it up


#1

I use spider and Ethernet J11d, when I disconnect the LAN cable I get eh CableConnectivity change event, so does happen when I reconnect. the problem is that a socket network which I accept through still return 10050 error which means network is down, only if I wait a little bit then it works fine.
my question is how can I detect this? when should I start running again the socket. accept after reconnecting?
can I get this info via socket/ ethernet built in?


#2

@ Devloper123 -

Can you please show your code?


#3

If the DHCP client gets the same IP, would the NetworkAddressChanged event still be fired?


#4

hi,
I am using Static IP.
this is similar to my code:



   private void CableConnectivityChanged(object sender, EthernetBuiltIn.CableConnectivityEventArgs e)
        {
            if (_ethernet.IsCableConnected)
            {
                _autoResetEvent.Set();
            }
            Debug.Print("Built-in Ethernet Cable is " + (_ethernet.IsCableConnected ? "Connected!" : "Disconneced!"));
        }

  public void Start() 
        {
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, port);
            socket.Bind(localEndPoint);
            socket.Listen(Int32.MaxValue);

            new Thread(StartServerInternal).Start();
        }

        private void StartServerInternal()
        {
            while (true)
            {
          try{
                // Wait for a request from a client.
                Socket clientSocket = socket.Accept();

                // Process the client request.
                var request = new ProcessClientRequest(this, clientSocket);
                request.Process();
       }
         catch(SocketException e)
           {
            _autoResetEvent.WaitOne();
            }
            }
        }

when reconnecting the autoResetEvnt in set and hte socket.Accept is called and throws a socket exception with error code 10050- network is down, while if I wait with a debugger a few seconds and then run the accept line is passes successfully.