so I'm trying to make a internet connection with c# using unity, and what I want to do is make the client to connect to the site, and load the data.
but there are cases there's lag, or weak connection, etc. that prevents you from getting connected, and I want the client to stop attempting to connect and just return connectionError or something like that after certain amount of time.
my code for this so far:
void HTTPRequest_TimeOut ( )
{
string url = "serverAddress";
HTTPRequest request = new HTTPRequest ( new Uri ( url ), (req, resp ) =>
{
switch ( req.State )
{
case HTTPRequestStates.Finished:
// utf-8 인코딩.
byte [] Bytes_For_Encoding = Encoding.UTF8.GetBytes ( resp.DataAsText );
string Encoded_String = Convert.ToBase64String ( Bytes_For_Encoding );
// utf-8 디코딩.
byte [] Decoded_Bytes = Convert.FromBase64String ( Encoded_String );
string Decoded_String = Encoding.UTF8.GetString ( Decoded_Bytes );
JsonData getdata = JsonMapper.ToObject ( Decoded_String );
DB_INPUT_test ( getdata, "items" );
break;
case HTTPRequestStates.Error:
Debug.LogError ( "Request Finished with Error! " );
break;
case HTTPRequestStates.Aborted:
Debug.LogWarning ( "Error : Request Aborted!" );
break;
case HTTPRequestStates.ConnectionTimedOut:
Debug.LogError ( "Error : Connection Timed Out!" );
break;
case HTTPRequestStates.TimedOut:
Debug.LogError ( "Error : Processing the request Timed Out!" );
break;
}
} );
request.Timeout = TimeSpan.FromSeconds ( 100 );
request.DisableCache = true;
request.Send ( );
}
at first I thought just changing request.Timeout would do the trick, I guess not?
currently if the connection is not strong(making mobile game) it just kinda "hangs" there, waiting for anything to load up.