AppInventor Web component, timeout

1,304 views
Skip to first unread message

TheJupiter732

unread,
Jun 10, 2016, 6:09:16 PM6/10/16
to mitappinv...@googlegroups.com
Hey!

I'm sending data to a mysql database with the web component.

Now, if there is lots of data or the data can not be send (bad internet connection, etc.)

the web component blocks further app interaction, or even blocks the whole smartphone.

Is there any way to set a timeout for the Web.GotText procedure?
Or exit it, if it takes too long?

Thank you for your answer!

Ghica

unread,
Jun 11, 2016, 10:39:12 AM6/11/16
to MIT App Inventor Forum
Maybe you could use a clock that you set when sending the data and disable when text is received.
But if it fires in the timer event, you would have reached your time-out and you can dispaly an error message, exit, or whatever.
Cheers, Ghica.

TheJupiter732

unread,
Jun 11, 2016, 12:36:50 PM6/11/16
to MIT App Inventor Forum
Yes, but just there is no function, or i didnt find it yet, to exit the Web component.

ScottFerguson

unread,
Jun 11, 2016, 2:20:43 PM6/11/16
to MIT App Inventor Forum
The Screen ErrorOccured block is triggered when there is a connection error.
You could display an error message if it is triggered.
---

TheJupiter732

unread,
Jun 11, 2016, 2:41:52 PM6/11/16
to MIT App Inventor Forum
Yep, that happens if there is no internet connection, of the request failed.

But if there is a connection, but it's just very slow or the server takes ages to respond, you can just wait for the HTTP request timeout.

Which is 300 seconds as far as i know.
You cant seem to break an successful connection progressing, until it times out.

Taifun

unread,
Jun 11, 2016, 4:11:31 PM6/11/16
to MIT App Inventor Forum
the web component blocks further app interaction, or even blocks the whole smartphone.
the web component works asynchronously and therefore can't block the UI thread...

It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 


TheJupiter732

unread,
Jun 11, 2016, 4:28:39 PM6/11/16
to mitappinv...@googlegroups.com
Hey taifun, i basically tried out your web to mysql script. (If you are that taifun from pura vida). (update: oh yes, you are)

The longer the mysql select, the longer it blocks the smartpone.
Not possible to enter anything else in the meantime.
Maybe only infrequent.

At the moment it writes "trying to execute query" it gets stuck.

Taifun

unread,
Jun 11, 2016, 6:58:53 PM6/11/16
to MIT App Inventor Forum
First of all you should understand the difference between "blocking the device" and the "time until you receive a response from your database"

As already said, the web component works asynchronously, which means, it can't block the UI thread. You can easily test that: just do something after calling the web.get method. This could be for example starting the clock component like this The 'Do something' example, or starting a video or doing anything you like... 

The question you should ask is, how can I reduce the time to get a result back from my database

The answer depends on
- your database model
- your primary keys, foreign keys and other indices you have defined
- the number of records in the tables
- your SELECT statement

Taifun

TheJupiter732

unread,
Jun 12, 2016, 8:35:43 PM6/12/16
to MIT App Inventor Forum
Hmm well , so:

If i send a web.post and i start a timer, and after 5 seconds, the web.get still didnt receive any data,
what would be the component to "drop" the post request?

web.delete? From reading what it does, i cant conclude that it does what i need.

PS: The database model is so simple, just a Select * with about 10 words, simple shopping list.
It usually is the connection, which doesnt work well.

Taifun

unread,
Jun 12, 2016, 9:11:46 PM6/12/16
to MIT App Inventor Forum
after sending something using the web component, there is no possibility to cancel it, you have to wait until you get a result 

you might want to tell us more about your table...

how many records does the table have?
how many records do you expect to get as result?
what is the CREATE TABLE statement of the table?
did you set primary and foreign keys?
how does the SELECT statement look like EXACTLY?

Taifun

Taifun

unread,
Jun 12, 2016, 9:21:09 PM6/12/16
to MIT App Inventor Forum
btw. for a shopping list, why do you need a server database? what about using a local database instead? 

see also my SQlite Extension to access the local SQlite database

The App Inventor Extensions are currently in testing. See the announcement for more information and read the App Inventor Extensions document about how to use an App Inventor Extension.

Taifun

TheJupiter732

unread,
Jun 12, 2016, 9:21:55 PM6/12/16
to MIT App Inventor Forum
"after sending something using the web component, there is no possibility to cancel it"
That's interesting.


Table currently has 134 records.

I want 5 records.

Created with phpmyadmin:
Index (int11, primary, auto_increment) -
name (varchar500, latin1_swedish_ci) -
timestamp (timestamp, default: current_timestamp)

Select * from mylist order by timestamp desc limit 5


TheJupiter732

unread,
Jun 12, 2016, 9:28:07 PM6/12/16
to MIT App Inventor Forum
"btw. for a shopping list, why do you need a server database? what about using a local database instead?"

You can look at your data online as well.
I thought in age of cloud computing, everything else then having your data everywhere everytime isnt cool anymore :)

Taifun

unread,
Jun 12, 2016, 9:36:35 PM6/12/16
to MIT App Inventor Forum
Table currently has 134 records.
well, that's nothing...

some recommendations:
1. do you really need varchar(500)? you could reduce that to the max. amount of characters you really need...
2. instead of using a separate column "Index" as primary key you probably could use the timestamp column as primary key?

I thought in age of cloud computing, everything else then having your data everywhere everytime isnt cool anymore :)
well, you said, you sometimes have a bad internet connection...
in this case you probably should think about it again if you really need "everywhere everytime"...

Taifun

TheJupiter732

unread,
Jun 12, 2016, 9:59:42 PM6/12/16
to MIT App Inventor Forum
Well with bad connection i dont mean slow (sorry, i forgot its common to say "bad" for "slow")...
If it is finally connected, it has about 20-30 mbit/s.

There is just no way to tell, if it is connected (Yeah, really).
It shows H+, but the connection seems to go into a sleep mode after some time,
and sometimes it really has a hard time to wake up. Sometimes only reboot helps.

So that's why i wanted to break after 5 secs, because then it sure isnt connected.
That little amount of data, even 2 secs should be enough to transmit.

So i guess it doesnt matter, how much data is transfered.

Maybe the device even blocks, because it tries to establish a connection?
Or that's a problem of the web component, althought it's asynchronous?
I don't know.


Ghica

unread,
Jun 13, 2016, 1:56:52 AM6/13/16
to MIT App Inventor Forum
What is the result if you do your query from a browser? Does it sometimes take long too? In a browser you have more possibilities to debug problems, for example using firebug. Is it a PHP script that does the query?
Cheers Ghica.

TheJupiter732

unread,
Jun 16, 2016, 4:17:40 PM6/16/16
to MIT App Inventor Forum
Hmm it's a POST, i dont know how to simulate a POST query.

Yes, it takes long or hangs completely, because it seems there is an active internet connection but it can not send/receive anything.
I dont know how this is called.

Connection established, data transfer not ready maybe?

Yes, php script does the query. I tried simulating a POST request, but even a linux sysadmin could not tell me how to do this.

Taifun

unread,
Jun 16, 2016, 4:48:59 PM6/16/16
to MIT App Inventor Forum
try another server, 
for a free webhost see also Q1 here http://puravidaapps.com/postfile.php#q
Taifun

Ghica

unread,
Jun 16, 2016, 6:58:34 PM6/16/16
to MIT App Inventor Forum
It would require to write some HTML with a form in it, that does a post. Usually you do a post when you want to store things, by convention, rather than retrieving information that would be done using get. Apart from that, the requests should not be different.
I am wondering now who uses your PHP script and how.
Cheers, Ghica.

TheJupiter732

unread,
Jun 17, 2016, 3:56:07 AM6/17/16
to MIT App Inventor Forum
Taifun, its definately not about the server, it's about the connection on the phone.

There is a connection to the internet, but no data transfer possible.
If you cant check this with app inventor beforehand, then i just simple have to wait.
Reply all
Reply to author
Forward
0 new messages