|
Using HTTP |
Top Previous Next |
The sock object can function as a HTTP server. This means that when certain conditions are met, individual sockets will switch into the HTTP mode and output the data in a style, consistent with the HTTP server functionality.
Certain BASIC information about the HTTP server has already been provided in Working with HTML and Embedding Code Within an HTML File.
When the socket is in the HTTP mode your program has no control over the RX buffer and only sometimes has control over the TX buffer. In this mode the RX buffer stores incoming HTTP requests from the client (browser) and the TX buffer is used to store HTTP replies. HTTP request is sent by the web browser and typically asks for a specific HTML page or another file. HTTP reply contains the data (page) being requested.
In the simplest case the file returned to the web browser is static- a "fixed" HTML page, a graphic, or some other file. Processing of such a static file requires no intervention from your program whatsoever. Just setup the socket(s) to be able to accept HTTP requests and the sock object will take care of the rest.
More often than not, however, you have to create a dynamic HTML page. Dynamic pages include fragments of BASIC code. When the sock object encounters such a fragment in the file being sent to the browser, it executes the code. This code, in turn, performs some action, for example, generates and sends some dynamic data to the browser or jumps to the other place in the HTML file.
The HTTP server built into the sock object understands two request types- GET and POST. Both can carry "variables" that the server will extract and pass to the BASIC code.
At the moment, the following file types are supported:
| • | HTML- can be static or include BASIC code. |
| • | TXT- plain text, no BASIC code can be included. |
| • | JPG and GIF- graphic files. |
|
Currently, the socket object can only access first 65534 bytes of each HTML file, even if the actual file is larger! Make sure that all HTML files in your project are not larger than 65534 bytes. This is not to be confused with the size of HTTP output generated by the file. A very large output can be generated by a small HTML file (due to dynamic data generation)- and that is OK. What's important is that the size of each HTML file in your project does not exceed 65534 bytes. 65534 is actually the size limitation for the compiled HTML file. When compiling your project, the TIDE will separate the static portion of the file from the Tibbo Basic code fragments. Only the static portion size matters. |