Skip to main content
Version: 20 R7 BETA

Web Server object

A 4D project can start and monitor a web server for the main (host) application as well as each hosted component.

For example, if you installed two components in your main application, you can start and monitor up to three independant web servers from your application:

  • one web server for the host application,
  • one web server for the component #1,
  • one web server for the component #2.

Other than memory, there is no limit to the number of components and thus, of web servers, that can be attached to a single 4D application project.

Each 4D web server, including the main application's web server, is exposed as a specific object of the 4D.WebServer class. Once instantiated, a web server object can be handled from the current application or from any component using a large number of properties and functions.

The legacy WEB commands of the 4D language are supported but cannot select the web server to which they apply (see below).

Each web server (host application or component) can be used in its own separate context, including:

  • On Web Authentication and On Web Connection database method calls
  • 4D tags processing and method calls,
  • web sessions and TLS protocol management.

This allows you to develop independant components and features that come with their own web interfaces.

Instantiating a web server object

The web server object of the host application (default web server) is automatically loaded by 4D at startup. Thus, if you write in a newly created project:

$nbSrv:=WEB Server list.length   
//$nbSrv value is 1

To instantiate a web server object, call the WEB Server command:

	//create an object variable of the 4D.WebServer class
var webServer : 4D.WebServer
//call the web server from the current context
webServer:=WEB Server

//equivalent to
webServer:=WEB Server(Web server database)

If the application uses components and you want to call:

  • the host application's web server from a component or
  • the server that received the request (whatever the server),

you can also use:

var webServer : 4D.WebServer 
//call the host web server from a component
webServer:=WEB Server(Web server host database)
//call the target web server
webServer:=WEB Server(Web server receiving request)

Web server functions

A web server class object contains the following functions:

FunctionsParameterReturn valueDescription
start()settings (object)status (object)Starts the web server
stop()--Stops the web server

To start and stop a web server, just call the start() and stop() functions of the web server object:

var $status : Object
//to start a web server with default settings
$status:=webServer.start()
//to start the web server with custom settings
//$settings object contains web server properties
webServer.start($settings)

//to stop the web server
$status:=webServer.stop()

Web server properties

A web server object contains various properties which configure the web server.

These properties are defined:

  1. using the settings parameter of the .start() function (except for read-only properties, see below),
  2. if not used, using the WEB SET OPTION command (host applications only),
  3. if not used, in the settings of the host application or the component.
  • If the web server is not started, the properties contain the values that will be used at the next web server startup.
  • If the web server is started, the properties contain the actual values used by the web server (default settings could have been overriden by the settings parameter of the .start() function.

isRunning, name, openSSLVersion, and perfectForwardSecrecy are read-only properties that cannot be predefined in the settings object parameter for the start() function.

Scope of the 4D Web commands

The 4D Language contains several commands that can be used to control the web server. However, these commands are designed to work with a single (default) web server. When using these commands in the context of web server objects, make sure their scope is appropriate.

CommandScope
SET DATABASE PARAMETERHost application web server
WEB CLOSE SESSIONWeb server that received the request
WEB GET BODY PARTWeb server that received the request
WEB Get body part countWeb server that received the request
WEB Get Current Session IDWeb server that received the request
WEB GET HTTP BODYWeb server that received the request
WEB GET HTTP HEADERWeb server that received the request
WEB GET OPTIONHost application web server
WEB Get server infoHost application web server
WEB GET SESSION EXPIRATIONWeb server that received the request
WEB Get session process countWeb server that received the request
WEB GET STATISTICSHost application web server
WEB GET VARIABLESWeb server that received the request
WEB Is secured connectionWeb server that received the request
WEB Is server runningHost application web server
WEB SEND BLOBWeb server that received the request
WEB SEND FILEWeb server that received the request
WEB SEND HTTP REDIRECTWeb server that received the request
WEB SEND RAW DATAWeb server that received the request
WEB SEND TEXTWeb server that received the request
WEB SET HOME PAGEHost application web server
WEB SET HTTP HEADERWeb server that received the request
WEB SET OPTIONHost application web server
WEB SET ROOT FOLDERHost application web server
WEB START SERVERHost application web server
WEB STOP SERVERHost application web server
WEB Validate digestWeb server that received the request