Build Version Cause Lag on certain computers.

Hi I have the following code connecting to the website:

public IEnumerator ConnectWebsite()
{

Connected = 0;
mainPage = new WWW (url);

while(!mainPage.isDone)
{
//Debug.Log(“Connecting”);
Connected = 0;
}//Wait untill download is done, insert custom loop here for dynamic wait screen \

yield return new WaitForSeconds (3);

if(mainPage.error != null)
{
//Debug.Log(“Can’t Connect to”);
Connected = 2;
}
else
{
Connected = 1;
}

}

I used coroutine at start, I build a verison of the game, and tested it on another computer and the computer I was devoloping on, what happend was that it loads really really slow, like everything get lagged, and then says: can’t connect to. However, On my computer, it connects fine without any lag at all.

Both Computer are on the same network, except the one using the build version had slower processing speed. Anybody know how I can get better connection off the different computers?

Does it have to do with sendrate in project settings, I modified it and no luck.

Thanks.

you are using totally bugged code, because you don’t have a yield so you totally halt the rest of the program with this coroutine (keep in mind, coroutine run in the same thread as the rest of the engine so an infinite loop in a coroutine means it will never return until its done, no other processing will happen)

while(!mainPage.isDone) 
{ 
//Debug.Log("Connecting"); 
Connected = 0; 
}//Wait untill download is done, insert custom loop here for dynamic wait screen \

should be

Connected = 0;
while(!mainPage.isDone) 
{ 
//Debug.Log("Connecting"); 
yield return new WaitForSeconds(0.1f);
}//Wait untill download is done, insert custom loop here for dynamic wait screen \

Um… Tried that still get the lag, also it’s not only for this code, but for all the networking code I have, such as posting highscore and stuff, it also seems that the slower the computer is(CPU wise), you get more chance of lag and no connection.

whereever you use WWW, ensure that your loops yield.
Don’t use !www.isDone in loops without having yields or you kill your application

I have some other functions such as WWW post highscore server side, used that only once, and everythign works fine in editor version, but once I compile it, on some computers just start lagging. Could it be it needs certain sdks or libs outside of unity compiled version?

the same stuff used in the editor is used outside too.

The difference is just that within the editor, forcefull “locking loops” get handled special as they otherwise would kill the whole editor due to such user errors.

Without code its impossible to say what might be causing it if you use coroutines and correctly yield whereever it has to wait for something to happen

void Update () {
///////////////////////////////////////////
// Internet Connection Checked.
// prompt user to enter account Information.
///////////////////////////////////////////

if(Connection == 0)
{

StartCoroutine(ConnectWebsite());

Connection = 1;

}
}

void OnGUI()
{

if(CheckConnection.Connected == 1)
SetupMenu();
else if(CheckConnection.Connected == 2)
DisplayQuit();

else
DisplayConnecting();

}

That’s it, and on one of my faster computer, both build version and editor version works just fine with connection.

The other one, after I correct the yields, it doesn’t have any more lag, but it still says Can’t connect to server.

Can or can not connect to server might highly depend on your server and if accessing the file is possible at all (you can check that by using exactly the same data in browser. Ensure to test without proxies and don’t forget that you don’t have HTTPS)

Also on a side note of above code:
I’m a bit stupid but you could kick the whole while ! isDone loop and just put a

yield return mainPage;

there if you do not do anything in the loop anyway.

Also once it is finished, you can check the error code in the WWW, that gives you an idea why it fails

after I get rid of the loop, seems like it won’t even connect during editor(not the .exe).

I am not using any proxies, and I am not sure what you mean by that I don’t have HTTPs? the build version doesn’t support www with connection to HTTP?

I executed the build version, and sometime it connects, sometime I get error: empty reply from server.

Any ideas?

Thanks.