Saltar al contenido principal
Versión: 20 R5 BETA

Objeto servidor web

Un proyecto 4D puede iniciar y monitorear un servidor web para la aplicación principal (host) así como para cada componente alojado.

Por ejemplo, si ha instalado dos componentes en su aplicación principal, puede iniciar y supervisar hasta tres servidores web independientes desde su aplicación:

  • un servidor web para la aplicación local,
  • un servidor web para el componente #1,
  • un servidor web para el componente #2.

Aparte de la memoria, no hay límite en el número de componentes y por lo tanto, de servidores web, que se pueden adjuntar a un solo proyecto de aplicación 4D.

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

Cada servidor web (aplicación local o componente) puede ser utilizado en su propio contexto independiente, incluyendo:

  • On Web Authentication and On Web Connection database method calls
  • el procesamiento de las etiquetas 4D y las llamadas de métodos,
  • sesiones web y gestión del protocolo TLS.

Esto le permite desarrollar componentes independientes y funcionalidades que vienen con sus propias interfaces web.

Instanciar un objeto servidor web

El objeto servidor web de la aplicación local (servidor web por defecto) es cargado automáticamente por 4D en al inicio. Por lo tanto, si escribe en un proyecto recién creado:

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

Si la aplicación utiliza componentes y quiere llamar a:

  • el servidor web de la aplicación local a partir de un componente o
  • el servidor que ha recibido la solicitud (sin importar el servidor),

también se puede utilizar:

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)

Funciones del servidor web

A web server class object contains the following functions:

FuncionesParámetrosValor devueltoDescripción
start()settings (objet)status (objeto)Iniciar el servidor web
stop()-*Detener el 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()

Propiedades del servidor web

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

Estas propiedades son 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. si no se utiliza, en los parámetros de la aplicación local o del componente.
  • Si el servidor web no se inicia, las propiedades contienen los valores que se utilizarán en el próximo inicio del servidor web.
  • 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.

Alcance de los comandos 4D Web

The 4D Language contains several commands that can be used to control the web server. Sin embargo, estos comandos están diseñados para trabajar con un único servidor web (por defecto). Cuando utilice estos comandos en el contexto de los objetos servidor web, asegúrese de que su alcance es el adecuado.

ComandoAlcance
SET DATABASE PARAMETERAplicación local del servidor web
WEB CLOSE SESSIONServidor web que ha recibido la petición
WEB GET BODY PARTServidor web que ha recibido la petición
WEB Get body part countServidor web que ha recibido la petición
WEB Get Current Session IDServidor web que ha recibido la petición
WEB GET HTTP BODYServidor web que ha recibido la petición
WEB GET HTTP HEADERServidor web que ha recibido la petición
WEB GET OPTIONAplicación local del servidor web
WEB Get server infoAplicación local del servidor web
WEB GET SESSION EXPIRATIONServidor web que ha recibido la petición
WEB Get session process countServidor web que ha recibido la petición
WEB GET STATISTICSAplicación local del servidor web
WEB GET VARIABLESServidor web que ha recibido la petición
WEB Is secured connectionServidor web que ha recibido la petición
WEB Is server runningAplicación local del servidor web
WEB SEND BLOBServidor web que ha recibido la petición
WEB SEND FILEServidor web que ha recibido la petición
WEB SEND HTTP REDIRECTServidor web que ha recibido la petición
WEB SEND RAW DATAServidor web que ha recibido la petición
WEB SEND TEXTServidor web que ha recibido la petición
WEB SET HOME PAGEAplicación local del servidor web
WEB SET HTTP HEADERServidor web que ha recibido la petición
WEB SET OPTIONAplicación local del servidor web
WEB SET ROOT FOLDERAplicación local del servidor web
WEB START SERVERAplicación local del servidor web
WEB STOP SERVERAplicación local del servidor web
WEB Validate digestServidor web que ha recibido la petición