public void connectOrDisconnect()
 {
     if (!justStateChange && EasyWiFiController.clientState == EasyWiFiConstants.CURRENT_CLIENT_STATE.NotConnected)
     {
         //not connected currently so try to connect
         justStateChange = true;
         EasyWiFiController.checkForServer();
         Invoke("resetDisconnection", 2f);
     }
     if (!justStateChange && EasyWiFiController.clientState == EasyWiFiConstants.CURRENT_CLIENT_STATE.SendingControllerData)
     {
         //connected currently so disconnect
         justStateChange = true;
         EasyWiFiController.sendDisconnect(EasyWiFiController.createDisconnectMessage());
         Invoke("resetDisconnection", 2f);
     }
 }
    void checkHeartbeatForTimeout()
    {
        if (EasyWiFiController.clientState == EasyWiFiConstants.CURRENT_CLIENT_STATE.SendingControllerData)
        {
            if ((DateTime.UtcNow - EasyWiFiController.lastHeartbeatTime).TotalSeconds > Convert.ToDouble(heartbeatTimeout))
            {
                consecutiveAttempts++;
                //we have passed the heartbeat timeout disconnect and go back to discovery mode
                if (consecutiveAttempts > 1)
                {
                    //disconnect

                    if (logVerbose)
                    {
                        Debug.Log("Heartbeat timeout. Going Back to Discovery Mode");
                    }
                    EasyWiFiController.clientState = EasyWiFiConstants.CURRENT_CLIENT_STATE.NotConnected;
                    consecutiveAttempts            = 0;

                    //take this time to set all the client side controls ready to reconnect
                    BaseControllerType temp;
                    if (EasyWiFiController.controllerDataDictionary != null)
                    {
                        foreach (string key in EasyWiFiController.controllerDataDictionary.Keys)
                        {
                            temp = EasyWiFiController.controllerDataDictionary[key];
                            temp.justReconnected = true;
                        }
                    }

                    //go back to discovery mode and check for a new server
                    EasyWiFiController.checkForServer();
                }
            }
        }
    }