Each nettobac session performs the following events
nOpen()
a connectionnPut
or nGet
)nClose()
the connection (optional)DELETE
the instanceWhen using the http utilities in file nettobac_http.bas, the minimum source code is
The above five steps are inside the function httpLoad(). After each step an error check gets done, and in case of an error the function breaks and returns the error code. See page Error Messages for details on possible error messages.
In case of success the function returns 0 (zero) and the downloaded context is in variable res
.
A little more complex code is used in the package examples, described in the following sections.
This example perfomrs a
data
"index.html"
: a text file (via http protocol)"fb_logo.gif"
: an image file (via http protocol)"osm.png"
: an image file created by php script (custom protocol)The downloads get done in function doClientActions(). Each one is enclosed by a SCOPE
block, in order to make it easy to add or remove further blocks.
When you execute this example (on the command line), it
data
in the executable pathdata
Check the files in folder src/bas/data
.
This example performs a
When you execute this example (on the command line), it outputs the following message
and waits for a client to connect. You can test this by starting your web browser and request the adress
That will open the "NetToBac HTML Demo #1" page, containing two links and a button.
Before you test the links, check the output on the command line. It shows further information on the actions performed by the example_server.bas code, ie. like
When the second link gets clicked, no further message gets shown in the command line window, since the browser connects to an external server to get the context.
When you click on the first (internal) link, further messages occur in the command line window (as shown above). The second page opens. It contains a form with two entries for a pseudo login and a button. When clicking the button, the server gets the form context and extracts the user input from the entries, to create a new page showing the results.
When the button Exit demo -> shutdown server
gets clicked, the server closes all connections and shuts down. This can also get achieved by pressing any key in the command line window.