Saltar para o conteúdo principal
Versão: v19

Objeto Web Server

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:

  • um servidor web para a aplicação local,
  • um servidor Web para o componente #1,
  • um servidor Web para o componente #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.

Os comandos WEB herdados da linguagem 4D são compatíveis, mas não é possível selecionar o servidor Web ao qual eles se aplicam (veja abaixo).

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
  • o processamento das etiquetas 4D e das chamadas de métodos,
  • sessões Web e gestão do protocolo TLS.

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

Instanciar um objeto servidor Web

The web server object of the host application (default web server) is automatically loaded by 4D at startup. Assim, se escrever num projeto recém-criado:

$nbSrv:=WEB Server list.length   
//$nbSrv valor é 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)

Se a aplicação utilizar componentes e o usuário pretender chamar:

  • o servidor Web da aplicação host a partir de um componente ou
  • o servidor que recebeu o pedido (qualquer que seja o servidor),

também pode ser utilizado:

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)

Funções do servidor Web

A web server class object contains the following functions:

FunçõesParâmetroValor retornadoDescrição
start()settings (objet)status (objecto)Inicia o servidor web
stop()--Pára o servidor Web

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()

Propriedades do servidor web

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

Estas propriedades são definidas:

  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. se não for usado, nos parâmetros da aplicação host ou do componente.
  • 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.

Âmbito dos comandos 4D Web

A linguagem 4D contém vários comandos que podem ser usados para controlar o servidor Web. 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.

ComandoÂmbito
SET DATABASE PARAMETERAplicação local de servidor Web
WEB CLOSE SESSIONServidor Web que recebeu o pedido
WEB GET BODY PARTServidor Web que recebeu o pedido
WEB Get body part countServidor Web que recebeu o pedido
WEB Get Current Session IDServidor Web que recebeu o pedido
WEB GET HTTP BODYServidor Web que recebeu o pedido
WEB GET HTTP HEADERServidor Web que recebeu o pedido
WEB GET OPTIONAplicação local de servidor Web
WEB Get server infoAplicação local de servidor Web
WEB GET SESSION EXPIRATIONServidor Web que recebeu o pedido
WEB Get session process countServidor Web que recebeu o pedido
WEB GET STATISTICSAplicação local de servidor Web
WEB GET VARIABLESServidor Web que recebeu o pedido
WEB Is secured connectionServidor Web que recebeu o pedido
WEB Is server runningAplicação local de servidor Web
WEB SEND BLOBServidor Web que recebeu o pedido
WEB SEND FILEServidor Web que recebeu o pedido
WEB SEND HTTP REDIRECTServidor Web que recebeu o pedido
WEB SEND RAW DATAServidor Web que recebeu o pedido
WEB SEND TEXTServidor Web que recebeu o pedido
WEB SET HOME PAGEAplicação local de servidor Web
WEB SET HTTP HEADERServidor Web que recebeu o pedido
WEB SET OPTIONAplicação local de servidor Web
WEB SET ROOT FOLDERAplicação local de servidor Web
WEB START SERVERAplicação local de servidor Web
WEB STOP SERVERAplicação local de servidor Web
WEB Validate digestServidor Web que recebeu o pedido