User Tools

Site Tools


Sidebar

Network and communication

k24:k24.6:start

24.6.0 Component gb.web

The web component gb.web allows you to develop a web application based on a CGI script using the following classes:

  • CGI,
  • WebPage,
  • Application,
  • Request,
  • Response,
  • Session,
  • URL,
  • URLQuery,
  • JSON and
  • JSONCollection.

They primarily use

  • the Request class to process an HTTP request,
  • generate an HTTP response using the Response class, and
  • access session data using the class Session.

To develop and test CGI web applications with the gb.web component, you need an HTTP server on your system, because web applications run on an HTTP server!

  • Variant 1
    You use the internal HTTP server (component gb.httpd). This HTTP server relies on the mini HTTP server thttpd, which comes from Jef Poskanzer. This way you can immediately test CGI web applications based on the integrated HTTP server component gb.httpd from within the IDE.
  • Variant 2
    You install and configure a (local) HTTP server. Chapter 24.13 Excursus describes the installation, configuration and testing of the Lighttpd web server in detail.

24.6.0.1 Excursus 1

The development of web applications with the components gb.web or also gb.web.gui only really makes sense if, on the system

  • the programming environment Gambas is installed and
  • an HTTP web server like Lighttpd or Apache2 is installed and configured for CGI,

so that you can actively work with Gambas generated web pages or the Gambas CGI scripts in the form of WebPages!

The Gambas Wiki and the Gambas Bugtracker are such web applications that are written in Gambas and run on a server that meets the above conditions. For most users, therefore, the only option is to test and run the developed web applications on a local server.

Notes:

  • After variant 1, it is possible to activate the menu item 'Use embedded HTTP server' in the project settings - the component gb.web must be loaded - in the menu 'Debug'.
  • The line 'UseHttpServer=1' is then automatically inserted into the project file .project.
  • The environment variable GB_HTTPD_PORT controls the port to which the server is bound. This allows the port to be changed.
  • The default port is 8080 for the embedded HTTP server.
  • The value for the environment variable GB_HTTPD_TIMEOUT determines a timeout in seconds.

Initial situation:

  • A WebPage (project name 'wpi') has been developed and tested in the IDE → menu item 'Use embedded HTTP server' is activated.
  • After starting the programme, the web page is displayed.
  • Executable programme file wpi.gambas has been saved.

(a) Change to the project folder of the WebPage:

hans@mint20:~/Schreibtisch$ cd wpi
hans@mint20:~/Schreibtisch/wpi$ GB_HTTPD_PORT=8080 gbx3

Result: Output of the HTML source code in the console.

(b) Change to the project folder of the WebPage and activate the embedded web server:

hans@mint20:~/Schreibtisch/wpi$ GB_HTTPD_PORT=8080 gbx3 --httpd  ' Alternative -H

This is the output in the console:

gb.httpd: bind 0.0.0.0 - Address already in use.

After calling it in the author's browser with http://localhost:8080 or localhost:8080 or 127.0.0.1:8080 or, for example, with http://192.168.2.106:8080, you will see the web page display in full epic width. You can cancel the interpreter with CTRL+C.

After copying the executable file wpi.gambas and the required files css/style.css and images/favicon.png into the web directory ~/public_html, the web page is displayed via the local web server Lighttpd with:

http://localhost/~hans/cgi-bin/wpi.gambas

BILD
Figure 24.6.0.1.1: Display in the web browser (Lighttpd)

24.6.0.2 Digression 2

You can use the three domains example.com or example.org or example.net as sample domain names in your examples (→ RFC 2606). Only these three reserved domains currently administered by the Internet Assigned Numbers Authority (IANA) can be used in your samples without any problems. You can find details on this topic on Daniel Rehbein's website at http://www.daniel-rehbein.de/rfc2606.html (→ as of 23.11.2020).

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k24/k24.6/start.txt · Last modified: 16.08.2022 (external edit)

Page Tools