メインコンテンツまでスキップ
バージョン: 20 R5 BETA

Webサーバーオブジェクト

4Dプロジェクトは、メイン (ホスト) アプリケーションおよび、ホストされた各コンポーネントの Webサーバーを起動して監視することができます。

たとえば、メインアプリケーションに 2つのコンポーネントをインストールしている場合、アプリケーションから最大 3つの独立した Webサーバーを起動して監視することができます:

  • ホストアプリケーションの Webサーバーを1つ
  • コンポーネント#1 の Webサーバーを1つ
  • コンポーネント#2 の Webサーバーを1つ

1つの 4Dアプリケーションプロジェクトに接続できるコンポーネントの数、つまり Webサーバーの数には、メモリ以外の制限はありません。

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

各 Webサーバー (ホストアプリケーションまたはコンポーネント) は、個別のコンテキストで使用できます。これには、以下が含まれます:

  • On Web Authentication and On Web Connection database method calls
  • 4Dタグの処理とメソッドの呼び出し
  • Webセッションや TLSプロトコルの管理

これにより、独自の Webインターフェースを備えた独立したコンポーネントや機能を開発することができます。

Webサーバーオブジェクトのインスタンス化

ホストアプリケーション (デフォルトWebサーバー) の Webサーバーオブジェクトは、4D 起動時に自動的に読み込まれます。 したがって、新規作成したプロジェクトに次のように書いた場合:

$nbSrv:=WEB Server list.length   
//$nbSrv の値は 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)

アプリケーションがコンポーネントを使用している場合に:

  • コンポーネントからホストアプリケーションの Webサーバーを呼び出す場合や
  • リクエストを受け取ったサーバー (どのサーバーでも) を呼び出す場合

次を使うこともできます:

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サーバー関数

A web server class object contains the following functions:

関数引数戻り値説明
start()settings (オブジェクト)status (オブジェクト)Webサーバーを開始します
stop()-*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()

Webサーバープロパティ

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

これらのプロパティは以下のように定義します:

  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. 上を使用しない場合は、ホストアプリケーションまたはコンポーネントの設定で定義します。
  • Webサーバーを起動していない場合、プロパティには 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.

4D Webコマンドのスコープ

The 4D Language contains several commands that can be used to control the web server. ただし、これらのコマンドは 1つの (デフォルト) Webサーバーで動作するように設計されています。 これらのコマンドを Webサーバーオブジェクトのコンテキストで使用する場合は、そのスコープが適切であることを確認してください。

コマンドスコープ
SET DATABASE PARAMETERホストアプリケーション Webサーバー
WEB CLOSE SESSIONリクエストを受け取った Webサーバー
WEB GET BODY PARTリクエストを受け取った Webサーバー
WEB Get body part countリクエストを受け取った Webサーバー
WEB Get Current Session IDリクエストを受け取った Webサーバー
WEB GET HTTP BODYリクエストを受け取った Webサーバー
WEB GET HTTP HEADERリクエストを受け取った Webサーバー
WEB GET OPTIONホストアプリケーション Webサーバー
WEB Get server infoホストアプリケーション Webサーバー
WEB GET SESSION EXPIRATIONリクエストを受け取った Webサーバー
WEB Get session process countリクエストを受け取った Webサーバー
WEB GET STATISTICSホストアプリケーション Webサーバー
WEB GET VARIABLESリクエストを受け取った Webサーバー
WEB Is secured connectionリクエストを受け取った Webサーバー
WEB Is server runningホストアプリケーション Webサーバー
WEB SEND BLOBリクエストを受け取った Webサーバー
WEB SEND FILEリクエストを受け取った Webサーバー
WEB SEND HTTP REDIRECTリクエストを受け取った Webサーバー
WEB SEND RAW DATAリクエストを受け取った Webサーバー
WEB SEND TEXTリクエストを受け取った Webサーバー
WEB SET HOME PAGEホストアプリケーション Webサーバー
WEB SET HTTP HEADERリクエストを受け取った Webサーバー
WEB SET OPTIONホストアプリケーション Webサーバー
WEB SET ROOT FOLDERホストアプリケーション Webサーバー
WEB START SERVERホストアプリケーション Webサーバー
WEB STOP SERVERホストアプリケーション Webサーバー
WEB Validate digestリクエストを受け取った Webサーバー