示例#1
0
 // Keep trying to connect until successful
 public IEnumerator KeepTryingToConnect()
 {
     // ensure is singleton
     if (connect_loop_running)
     {
         Debug.Log("Connection management loop already running!");
         yield break;
     }
     // run forever, so auto-reconnect if connection is dropped
     while (true)
     {
         connect_loop_running = true;
         if (!nt.isConnected())
         {
             tryToConnect(100);
         }
         else
         {
             last_connected_time = nt.getTimeStamp();
         }
         // check again in .5s
         yield return(new WaitForSeconds(.5f));
     }
     connect_loop_running = false;
 }
 public void tryToConnect(int timeout_ms)
 {
     // TODO [x] : This is evil as it blocks the main graphics thread for 500ms!!
     //     should refactor nt into a co-routine? to not block in this way...
     Debug.Log("Trying to connect to : " + decoderAddress);
     // TODO [] : Add a user query if the connection doesn't work for too long.
     nt.connect(decoderAddress, -1, timeout_ms);
     if (nt.isConnected())
     {
         Debug.Log("Connected to " + nt.getHostPort());
         nt.modeChange("idle");
         if (connectedEvent != null)
         {
             connectedEvent.Invoke();
         }
     }
 }