Beispiel #1
0
 void CheckHeartBeat()
 {
     while (!asyncTcpClient.isConnected)
     {
         Loom.WaitForSeconds(exitTime);
         if (!heartBeat)
         {
             LogTool.Log("连接不到服务器");
         }
         heartBeat = false;
     }
 }
    private void ContinuesSingleThreadCoroutine()
    {
        Debug.Log("Starting an never ending Coroutine on a seperate Thread!");
        while (true)
        {
            Loom.WaitForNextFrame(10);
            Loom.DispatchToMainThread(() => Debug.Log("I waited atleast 10 frames. Whats the current frameCount? : " + Time.frameCount), true);

            Loom.WaitForSeconds(1);
            Loom.DispatchToMainThread(() => Debug.Log("I waited atleast 1 second. Whats the current frameCount? : " + Time.frameCount), true);
        }
        Debug.Log("It will never get here, but thats oke...");
    }
 private void HeartBeat()
 {
     while (tcpServer.isRunning)
     {
         Loom.WaitForSeconds(beatTime);
         if (tcpServer != null)
         {
             Loom.DispatchToMainThread(() =>
             {
                 //NGUIDebug.Log(Command.HEART_BEAT);
                 tcpServer.HeartBeat();
             }, true);
         }
     }
 }
    //--------------- Managing a simple single Thread --------------------
    private void EndingSingleThreadCoroutine()
    {
        Debug.Log("Starting an Coroutine on a seperate Thread!");

        Loom.WaitForNextFrame(30);
        Loom.DispatchToMainThread(() => Debug.Log("I waited atleast 30 frames. Whats the current frameCount? : " + Time.frameCount), true);

        Loom.WaitForSeconds(10);
        Loom.DispatchToMainThread(() => Debug.Log("I waited atleast 10 seconds. Whats the current frameCount? : " + Time.frameCount), true);

        //Throw error to show safemode nicely throws errors in the MainThread.

        Debug.LogWarning("About the throw an error...");
        throw new Exception("This is an safe Error and should showup in the Console");

        Debug.Log("It won't get here, but the Thread will die anyways.");
    }
Beispiel #5
0
 // Update is called once per frame
 void ClientConnect()
 {
     try
     {
         if (asyncTcpClient != null)
         {
             while (!asyncTcpClient.isConnected && asyncTcpClient.tcpClient.Poll(connectTime, System.Net.Sockets.SelectMode.SelectRead))
             {
                 Loom.DispatchToMainThread(() => asyncTcpClient.Connet());
                 Loom.WaitForSeconds(connectTime);
                 count++;
             }
             if (count > exitTime)
             {
                 count = 0;
                 Loom.DispatchToMainThread(() => closeTCP());
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 private void CheckHeatBeat()
 {
     while (tcpServer.isRunning)
     {
         Loom.WaitForSeconds(ExitTime);
         if (tcpServer != null && tcpServer.clientDic != null && tcpServer.clientCount > 0)
         {
             foreach (var item in tcpServer.clientDic)
             {
                 if (item.Value.isRunning)
                 {
                     if (!item.Value.CheckHeartBeat())
                     {
                         tcpServer.Close(item.Value);
                     }
                 }
             }
         }
         else
         {
             return;
         }
     }
 }