# Class TCEFServerComponent

Description
Hierarchy
Fields
Methods
Properties

## Unit

uCEFServerComponent

## Declaration

`type TCEFServerComponent = class(TComponent, IServerEvents)`

## Description

The TCEFServerComponent class puts together all CEF server procedures, functions, properties and events in one place.

## Hierarchy

- TObject
- TPersistent
- TComponent
- TCEFServerComponent

## Overview

### Fields

Protected | `FHandler: ICefServerHandler;`
Protected | `FServer: ICefServer;`
Protected | `FInitialized: boolean;`
Protected | `FOnServerCreated: TOnServerCreated;`
Protected | `FOnServerDestroyed: TOnServerDestroyed;`
Protected | `FOnClientConnected: TOnClientConnected;`
Protected | `FOnClientDisconnected: TOnClientDisconnected;`
Protected | `FOnHttpRequest: TOnHttpRequest;`
Protected | `FOnWebSocketRequest: TOnWebSocketRequest;`
Protected | `FOnWebSocketConnected: TOnWebSocketConnected;`
Protected | `FOnWebSocketMessage: TOnWebSocketMessage;`

### Methods

Protected | `function GetInitialized: boolean;`
Protected | `function GetIsRunning: boolean;`
Protected | `function GetAddress: ustring;`
Protected | `function GetHasConnection: boolean;`
Protected | `procedure doOnServerCreated(const server: ICefServer); virtual;`
Protected | `procedure doOnServerDestroyed(const server: ICefServer); virtual;`
Protected | `procedure doOnClientConnected(const server: ICefServer; connection_id: Integer); virtual;`
Protected | `procedure doOnClientDisconnected(const server: ICefServer; connection_id: Integer); virtual;`
Protected | `procedure doOnHttpRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest); virtual;`
Protected | `procedure doOnWebSocketRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest; const callback: ICefCallback); virtual;`
Protected | `procedure doOnWebSocketConnected(const server: ICefServer; connection_id: Integer); virtual;`
Protected | `procedure doOnWebSocketMessage(const server: ICefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); virtual;`
Protected | `procedure InitializeEvents;`
Public | `constructor Create(AOwner: TComponent); override;`
Public | `destructor Destroy; override;`
Public | `procedure CreateServer(const address : ustring = DEFAULT_CEFSERVER_ADDRESS; port : uint16 = DEFAULT_CEFSERVER_PORT; backlog : Integer = DEFAULT_CEFSERVER_BACKLOG);`
Public | `procedure Shutdown;`
Public | `function IsValidConnection(connection_id: Integer) : boolean;`
Public | `procedure SendHttp200response(connection_id: Integer; const content_type: ustring; const data: Pointer; data_size: NativeUInt);`
Public | `procedure SendHttp404response(connection_id: Integer);`
Public | `procedure SendHttp500response(connection_id: Integer; const error_message: ustring);`
Public | `procedure SendHttpResponse(connection_id, response_code: Integer; const content_type: ustring; content_length: int64; const extra_headers: ICefStringMultimap);`
Public | `procedure SendRawData(connection_id: Integer; const data: Pointer; data_size: NativeUInt);`
Public | `procedure CloseConnection(connection_id: Integer);`
Public | `procedure SendWebSocketMessage(connection_id: Integer; const data: Pointer; data_size: NativeUInt);`

### Properties

Public | `property Initialized : boolean read GetInitialized;`
Public | `property IsRunning : boolean read GetIsRunning;`
Public | `property Address : ustring read GetAddress;`
Public | `property HasConnection : boolean read GetHasConnection;`
Published | `property OnServerCreated : TOnServerCreated read FOnServerCreated write FOnServerCreated;`
Published | `property OnServerDestroyed : TOnServerDestroyed read FOnServerDestroyed write FOnServerDestroyed;`
Published | `property OnClientConnected : TOnClientConnected read FOnClientConnected write FOnClientConnected;`
Published | `property OnClientDisconnected : TOnClientDisconnected read FOnClientDisconnected write FOnClientDisconnected;`
Published | `property OnHttpRequest : TOnHttpRequest read FOnHttpRequest write FOnHttpRequest;`
Published | `property OnWebSocketRequest : TOnWebSocketRequest read FOnWebSocketRequest write FOnWebSocketRequest;`
Published | `property OnWebSocketConnected : TOnWebSocketConnected read FOnWebSocketConnected write FOnWebSocketConnected;`
Published | `property OnWebSocketMessage : TOnWebSocketMessage read FOnWebSocketMessage write FOnWebSocketMessage;`

## Description

### Fields

Protected | `FHandler: ICefServerHandler;`
This item has no description.

Protected | `FServer: ICefServer;`
This item has no description.

Protected | `FInitialized: boolean;`
This item has no description.

Protected | `FOnServerCreated: TOnServerCreated;`
IServerEvents

Protected | `FOnServerDestroyed: TOnServerDestroyed;`
This item has no description.

Protected | `FOnClientConnected: TOnClientConnected;`
This item has no description.

Protected | `FOnClientDisconnected: TOnClientDisconnected;`
This item has no description.

Protected | `FOnHttpRequest: TOnHttpRequest;`
This item has no description.

Protected | `FOnWebSocketRequest: TOnWebSocketRequest;`
This item has no description.

Protected | `FOnWebSocketConnected: TOnWebSocketConnected;`
This item has no description.

Protected | `FOnWebSocketMessage: TOnWebSocketMessage;`
This item has no description.

### Methods

Protected | `function GetInitialized: boolean;`
This item has no description.

Protected | `function GetIsRunning: boolean;`
This item has no description.

Protected | `function GetAddress: ustring;`
This item has no description.

Protected | `function GetHasConnection: boolean;`
This item has no description.

Protected | `procedure doOnServerCreated(const server: ICefServer); virtual;`
IServerEvents

Protected | `procedure doOnServerDestroyed(const server: ICefServer); virtual;`
This item has no description.

Protected | `procedure doOnClientConnected(const server: ICefServer; connection_id: Integer); virtual;`
This item has no description.

Protected | `procedure doOnClientDisconnected(const server: ICefServer; connection_id: Integer); virtual;`
This item has no description.

Protected | `procedure doOnHttpRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest); virtual;`
This item has no description.

Protected | `procedure doOnWebSocketRequest(const server: ICefServer; connection_id: Integer; const client_address: ustring; const request: ICefRequest; const callback: ICefCallback); virtual;`
This item has no description.

Protected | `procedure doOnWebSocketConnected(const server: ICefServer; connection_id: Integer); virtual;`
This item has no description.

Protected | `procedure doOnWebSocketMessage(const server: ICefServer; connection_id: Integer; const data: Pointer; data_size: NativeUInt); virtual;`
This item has no description.

Protected | `procedure InitializeEvents;`
This item has no description.

Public | `constructor Create(AOwner: TComponent); override;`
This item has no description.

Public | `destructor Destroy; override;`
This item has no description.

Public | `procedure CreateServer(const address : ustring = DEFAULT_CEFSERVER_ADDRESS; port : uint16 = DEFAULT_CEFSERVER_PORT; backlog : Integer = DEFAULT_CEFSERVER_BACKLOG);`
Create a new server that binds to |address| and |port|. |address| must be a valid IPv4 or IPv6 address (e.g. 127.0.0.1 or ::1) and |port| must be a port number outside of the reserved range (e.g. between 1025 and 65535 on most platforms). |backlog| is the maximum number of pending connections. A new thread will be created for each CreateServer call (the "dedicated server thread"). It is therefore recommended to use a different ICefServerHandler instance for each CreateServer call to avoid thread safety issues in the ICefServerHandler implementation. The ICefServerHandler.OnServerCreated function will be called on the dedicated server thread to report success or failure. See ICefServerHandler.OnServerCreated documentation for a description of server lifespan.

Public | `procedure Shutdown;`
Stop the server and shut down the dedicated server thread. See ICefServerHandler.OnServerCreated documentation for a description of server lifespan.

Public | `function IsValidConnection(connection_id: Integer) : boolean;`
Returns true (1) if |connection_id| represents a valid connection. This function must be called on the dedicated server thread.

Public | `procedure SendHttp200response(connection_id: Integer; const content_type: ustring; const data: Pointer; data_size: NativeUInt);`
Send an HTTP 200 "OK" response to the connection identified by |connection_id|. |content_type| is the response content type (e.g. "text/html"), |data| is the response content, and |data_size| is the size of |data| in bytes. The contents of |data| will be copied. The connection will be closed automatically after the response is sent.

Public | `procedure SendHttp404response(connection_id: Integer);`
Send an HTTP 404 "Not Found" response to the connection identified by |connection_id|. The connection will be closed automatically after the response is sent.

Public | `procedure SendHttp500response(connection_id: Integer; const error_message: ustring);`
Send an HTTP 500 "Internal Server Error" response to the connection identified by |connection_id|. |error_message| is the associated error message. The connection will be closed automatically after the response is sent.

Public | `procedure SendHttpResponse(connection_id, response_code: Integer; const content_type: ustring; content_length: int64; const extra_headers: ICefStringMultimap);`
Send a custom HTTP response to the connection identified by |connection_id|. |response_code| is the HTTP response code sent in the status line (e.g. 200), |content_type| is the response content type sent as the "Content-Type" header (e.g. "text/html"), |content_length| is the expected content length, and |extra_headers| is the map of extra response headers. If |content_length| is >= 0 then the "Content-Length" header will be sent. If |content_length| is 0 then no content is expected and the connection will be closed automatically after the response is sent. If |content_length| is < 0 then no "Content-Length" header will be sent and the client will continue reading until the connection is closed. Use the SendRawData function to send the content, if applicable, and call CloseConnection after all content has been sent.

Public | `procedure SendRawData(connection_id: Integer; const data: Pointer; data_size: NativeUInt);`
Send raw data directly to the connection identified by |connection_id|. |data| is the raw data and |data_size| is the size of |data| in bytes. The contents of |data| will be copied. No validation of |data| is performed internally so the client should be careful to send the amount indicated by the "Content-Length" header, if specified. See SendHttpResponse documentation for intended usage.

Public | `procedure CloseConnection(connection_id: Integer);`
Close the connection identified by |connection_id|. See SendHttpResponse documentation for intended usage.

Public | `procedure SendWebSocketMessage(connection_id: Integer; const data: Pointer; data_size: NativeUInt);`
Send a WebSocket message to the connection identified by |connection_id|. |data| is the response content and |data_size| is the size of |data| in bytes. The contents of |data| will be copied. See ICefServerHandler.OnWebSocketRequest documentation for intended usage.

### Properties

Public | `property Initialized : boolean read GetInitialized;`
Returns true when the server and the handler are initialized.

Public | `property IsRunning : boolean read GetIsRunning;`
Returns true (1) if the server is currently running and accepting incoming connections. See ICefServerHandler.OnServerCreated documentation for a description of server lifespan. This function must be called on the dedicated server thread.

Public | `property Address : ustring read GetAddress;`
Returns the server address including the port number.

Public | `property HasConnection : boolean read GetHasConnection;`
Returns true (1) if the server currently has a connection. This function must be called on the dedicated server thread.

Published | `property OnServerCreated : TOnServerCreated read FOnServerCreated write FOnServerCreated;`
Called when |server| is created. If the server was started successfully then ICefServer.IsRunning will return true (1). The server will continue running until ICefServerShutdown is called, after which time OnServerDestroyed will be called. If the server failed to start then OnServerDestroyed will be called immediately after this function returns. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnServerDestroyed : TOnServerDestroyed read FOnServerDestroyed write FOnServerDestroyed;`
Called when |server| is destroyed. The server thread will be stopped after this function returns. The client should release any references to |server| when this function is called. See OnServerCreated documentation for a description of server lifespan. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnClientConnected : TOnClientConnected read FOnClientConnected write FOnClientConnected;`
Called when a client connects to |server|. |connection_id| uniquely identifies the connection. Each call to this function will have a matching call to OnClientDisconnected. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnClientDisconnected : TOnClientDisconnected read FOnClientDisconnected write FOnClientDisconnected;`
Called when a client disconnects from |server|. |connection_id| uniquely identifies the connection. The client should release any data associated with |connection_id| when this function is called and |connection_id| should no longer be passed to ICefServer functions. Disconnects can originate from either the client or the server. For example, the server will disconnect automatically after a ICefServer.SendHttpXXXResponse function is called. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnHttpRequest : TOnHttpRequest read FOnHttpRequest write FOnHttpRequest;`
Called when |server| receives an HTTP request. |connection_id| uniquely identifies the connection, |client_address| is the requesting IPv4 or IPv6 client address including port number, and |request| contains the request contents (URL, function, headers and optional POST data). Call ICefServer functions either synchronously or asynchronusly to send a response. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnWebSocketRequest : TOnWebSocketRequest read FOnWebSocketRequest write FOnWebSocketRequest;`
Called when |server| receives a WebSocket request. |connection_id| uniquely identifies the connection, |client_address| is the requesting IPv4 or IPv6 client address including port number, and |request| contains the request contents (URL, function, headers and optional POST data). Execute |callback| either synchronously or asynchronously to accept or decline the WebSocket connection. If the request is accepted then OnWebSocketConnected will be called after the WebSocket has connected and incoming messages will be delivered to the OnWebSocketMessage callback. If the request is declined then the client will be disconnected and OnClientDisconnected will be called. Call the ICefServer.SendWebSocketMessage function after receiving the OnWebSocketConnected callback to respond with WebSocket messages. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnWebSocketConnected : TOnWebSocketConnected read FOnWebSocketConnected write FOnWebSocketConnected;`
Called after the client has accepted the WebSocket connection for |server| and |connection_id| via the OnWebSocketRequest callback. See OnWebSocketRequest documentation for intended usage. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Published | `property OnWebSocketMessage : TOnWebSocketMessage read FOnWebSocketMessage write FOnWebSocketMessage;`
Called when |server| receives an WebSocket message. |connection_id| uniquely identifies the connection, |data| is the message content and |data_size| is the size of |data| in bytes. Do not keep a reference to |data| outside of this function. See OnWebSocketRequest documentation for intended usage. This event will be called on the CEF server thread. <see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_server_capi.h">CEF source file: /include/capi/cef_server_capi.h (cef_server_handler_t))

Generated by PasDoc 1.0.4.