EMX Watchdog Query

[quote=“Brett”]
if you can count the failures, you’re obviously handling them appropriately.[/quote]

And reset the counter by the watchdog :stuck_out_tongue: (just kidding…)

The problem is, that I don’t get timeout, if a server is down. So I create new thread and make join with main thread for 10 seconds. But with a number of failed threads the application hangs. I wasn’t found timeout parameter for socket server request.

ok, so you have gone to quite a length to protect yourself from that scenario. I still ask what benefit you get by restarting - do things then magically work? (I now think watchdog is probably the right hammer for your nail :slight_smile: )

Could you explain this, maybe show some code to understand.

When I restart spider, i have again approx 100 tries. I don’t know why there is no throwing exception, when client couldn’t reach server, and i assume that netmf doesn’t run garbage collector on these threads. I was trying to force garbage collector, but this didn’t solve my problem. Also i was setting socket options to no delay, which also didn’t work…

@ David@ Emrol -
This is my code


private static bool SendMessage(string sValue)
        {
            if (ConnectionProxy.ConnectableWrapper == null) return false;

            Thread tSendServerBugWrapper = new Thread(() => SendMessageWorker(sValue));
            tSendServerBugWrapper.Start();

            tSendServerBugWrapper.Join(10000);
            bool bIsSuspended = false;
            if (tSendServerBugWrapper.IsAlive)
            {
                Debug.Print("Send server thread killed...");
                bIsSuspended = true;
                tSendServerBugWrapper.Suspend();
            }

            if (!m_IsLastSendingSucceded || bIsSuspended)
            {
                Debug.Print("Writting message to the store...");
                PersistanceStorage.WriteToPersistanceStorage(Logging.StoreFileFileName, sValue, true);
                if (m_Retries > ApplicationSettings.Retries)
                    PowerState.RebootDevice(false);

                m_Retries = m_Retries + 1;
                Debug.Print("End writting message to the store. Sending attempt " + m_Retries + " of " + ApplicationSettings.Retries);
                return false;
            }
            else
            {
                m_Retries = 0;
                return true;
            }
        }

And the actual code from the Thread please, i’m closing down for today, looking back tomorrow.

The code which sends data is (I never reach exception)


public bool SendData2Server(byte[] msg)
        {
            try
            {
                using (Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
                    clientSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
                    clientSocket.Connect(serverEndPoint);
                    clientSocket.Send(msg);
                    clientSocket.Close();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }

But don’t bother whith this. I’ll use watchdog, and maybe in 4.3, the sockets would have some timeout or something… Thanks anyway

Ok, good luck and have fun !

You too :slight_smile: