321
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
device, so "polite" waiting shall include a
statement:
<?
dim
s
as
string
(
4
)
?>
<!DOCTYPE HTML
public
"-//W3C//DTD W3 HTML//EN"
>
<HTML>
<BODY>
The state of line
0
is:!<br>
<?
'This is a BASIC code snippet. Get the state of the line.
io.num=
0
if
io.state= LOW
then
s=
"LOW"
else
s=HIGH
end
if
'and now we wait till the TX buffer has enough free space
while
sock.txfree<len(s)
doevents
wend
'OK, so necessary space is now available!
sock.setdata(s)
sock.send
?>
</BODY>
</HTML>
Now we have a bullet-proof dynamic content generation and non-blocking
operation! As you get more experience with HTML, you will see that the doevents
statement has to be used quite often.
Special case: doevents and concurrent request of the same file
With HTTP it is entirely possible that two computers (browsers) will request the
same HTML file. If you have allocated more than one socket for HTTP it is also
possible that both of those requests will be processed at the same time. Of course,
the BASIC VM is a single-process system, so when it comes to processing dynamic
part of the files, one of the requests will be first.
It is also entirely possible, that when executing the BASIC procedure from the first
"instance" of the file, execution arrives at doevents and the second instance of the
same file will start to process. After all, doevents allows other events to execute,
so this can include activity in other sockets.
Now, if the same BASIC procedure was allowed to execute again this would cause
recursion: an attempt to execute a portion of code while it is already executing!
, so the VM will not re-enter the code immediately.
Instead, the second instance of HTML page will be "on hold" until the first instance
finishes running the procedure in question. After that, the same procedure will be
executed for the second instance. This behavior has been introduced in
V1.2
of
TiOS. In the previous release, procedure execution for the second instance of the
HTML page was simply skipped and not executed at all, which is wrong!
Once again, for this to occur the following conditions must be met: the HTML
procedure in question must use doevents statement, and the same file (HTML
page) must be requested simultaneously from several browsers.
Avoiding illegal characters
82
62