Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

WWW class timeout

Discussion in 'Scripting' started by waneck, Apr 1, 2011.

  1. waneck

    waneck

    Joined:
    Apr 25, 2009
    Posts:
    8
    Hi there!

    Is it possible to change the WWW class timeout value? I wanted to implement a comet-style server so timeout should be set to its max as possible value!

    Thank you!
    Cauê
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No, you can not impact the WWW timeout.
    On the browser its controlled fully by the browser which it uses, on other platforms its related to limitations of those platforms
     
  3. waneck

    waneck

    Joined:
    Apr 25, 2009
    Posts:
    8
    Thanks !
     
  4. flamy

    flamy

    Joined:
    Feb 7, 2011
    Posts:
    194
    you can actually create a fake time out like this!!!

    Code (csharp):
    1.  
    2.          float ServerConnectionTimeout=2f;
    3. private IEnumerator PingToServer()
    4.     {
    5.        
    6.         string post_url=phpPath+"checkinternet.php";
    7.        
    8.         WWW hs_post=new WWW (post_url);
    9.         //yield return hs_post;
    10.         float tempTime=0;
    11.         while(!hs_post.isDone  hs_post.error==null  tempTime<ServerConnectionTimeOut)
    12.         {
    13.            
    14.             tempTime+=Time.deltaTime;
    15.             yield return 0;
    16.         }
    17.        
    18.        
    19.         if (hs_post.error != null   || tempTime>=ServerConnectionTimeOut)
    20.         {
    21.          
    22.             //print(hs_post.error);
    23.             isOnline=false;
    24.         }
    25.         else
    26.         {
    27.             //handle your online data!!
    28. //          print(hs_post.text);
    29.  
    30.                          // this is a sample to check internet connection
    31.             if(hs_post.text=="true")
    32.             {
    33.                 isOnline=true;                             
    34.             }
    35.             else
    36.             {
    37.                 isOnline=false;
    38.             }
    39.            
    40.            
    41.         }
    42.     }
    43.  
     
    ___Petr___ likes this.
  5. ___Petr___

    ___Petr___

    Joined:
    Jun 4, 2013
    Posts:
    40
    In the case
    Code (csharp):
    1. tempTime>=ServerConnectionTimeOut && !hs_post.isDone && hs_post.error==null
    I think I need to call hs_post.Dispose().