Chromium Embedded Framework (CEF)  116.0.6+gc182ee2+chromium-116.0.5845.10
CefServerHandler Class Referenceabstract

Implement this interface to handle HTTP server requests. More...

#include "include/cef_server.h"

Inheritance diagram for CefServerHandler:
CefBaseRefCounted

Public Member Functions

virtual void OnServerCreated (CefRefPtr< CefServer > server)=0
 Called when |server| is created. More...
 
virtual void OnServerDestroyed (CefRefPtr< CefServer > server)=0
 Called when |server| is destroyed. More...
 
virtual void OnClientConnected (CefRefPtr< CefServer > server, int connection_id)=0
 Called when a client connects to |server|. More...
 
virtual void OnClientDisconnected (CefRefPtr< CefServer > server, int connection_id)=0
 Called when a client disconnects from |server|. More...
 
virtual void OnHttpRequest (CefRefPtr< CefServer > server, int connection_id, const CefString &client_address, CefRefPtr< CefRequest > request)=0
 Called when |server| receives an HTTP request. More...
 
virtual void OnWebSocketRequest (CefRefPtr< CefServer > server, int connection_id, const CefString &client_address, CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback)=0
 Called when |server| receives a WebSocket request. More...
 
virtual void OnWebSocketConnected (CefRefPtr< CefServer > server, int connection_id)=0
 Called after the client has accepted the WebSocket connection for |server| and |connection_id| via the OnWebSocketRequest callback. More...
 
virtual void OnWebSocketMessage (CefRefPtr< CefServer > server, int connection_id, const void *data, size_t data_size)=0
 Called when |server| receives an WebSocket message. More...
 
- Public Member Functions inherited from CefBaseRefCounted
virtual void AddRef () const =0
 Called to increment the reference count for the object. More...
 
virtual bool Release () const =0
 Called to decrement the reference count for the object. More...
 
virtual bool HasOneRef () const =0
 Returns true if the reference count is 1. More...
 
virtual bool HasAtLeastOneRef () const =0
 Returns true if the reference count is at least 1. More...
 

Additional Inherited Members

- Protected Member Functions inherited from CefBaseRefCounted
virtual ~CefBaseRefCounted ()
 

Detailed Description

Implement this interface to handle HTTP server requests.

A new thread will be created for each CefServer::CreateServer call (the "dedicated server thread"), and the methods of this class will be called on that thread. It is therefore recommended to use a different CefServerHandler instance for each CefServer::CreateServer call to avoid thread safety issues in the CefServerHandler implementation.

Member Function Documentation

◆ OnClientConnected()

virtual void CefServerHandler::OnClientConnected ( CefRefPtr< CefServer server,
int  connection_id 
)
pure virtual

Called when a client connects to |server|.

|connection_id| uniquely identifies the connection. Each call to this method will have a matching call to OnClientDisconnected.

◆ OnClientDisconnected()

virtual void CefServerHandler::OnClientDisconnected ( CefRefPtr< CefServer server,
int  connection_id 
)
pure virtual

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 method is called and |connection_id| should no longer be passed to CefServer methods. Disconnects can originate from either the client or the server. For example, the server will disconnect automatically after a CefServer::SendHttpXXXResponse method is called.

◆ OnHttpRequest()

virtual void CefServerHandler::OnHttpRequest ( CefRefPtr< CefServer server,
int  connection_id,
const CefString client_address,
CefRefPtr< CefRequest request 
)
pure virtual

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, method, headers and optional POST data). Call CefServer methods either synchronously or asynchronusly to send a response.

◆ OnServerCreated()

virtual void CefServerHandler::OnServerCreated ( CefRefPtr< CefServer server)
pure virtual

Called when |server| is created.

If the server was started successfully then CefServer::IsRunning will return true. The server will continue running until CefServer::Shutdown is called, after which time OnServerDestroyed will be called. If the server failed to start then OnServerDestroyed will be called immediately after this method returns.

◆ OnServerDestroyed()

virtual void CefServerHandler::OnServerDestroyed ( CefRefPtr< CefServer server)
pure virtual

Called when |server| is destroyed.

The server thread will be stopped after this method returns. The client should release any references to |server| when this method is called. See OnServerCreated documentation for a description of server lifespan.

◆ OnWebSocketConnected()

virtual void CefServerHandler::OnWebSocketConnected ( CefRefPtr< CefServer server,
int  connection_id 
)
pure virtual

Called after the client has accepted the WebSocket connection for |server| and |connection_id| via the OnWebSocketRequest callback.

See OnWebSocketRequest documentation for intended usage.

◆ OnWebSocketMessage()

virtual void CefServerHandler::OnWebSocketMessage ( CefRefPtr< CefServer server,
int  connection_id,
const void *  data,
size_t  data_size 
)
pure virtual

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 method. See OnWebSocketRequest documentation for intended usage.

◆ OnWebSocketRequest()

virtual void CefServerHandler::OnWebSocketRequest ( CefRefPtr< CefServer server,
int  connection_id,
const CefString client_address,
CefRefPtr< CefRequest request,
CefRefPtr< CefCallback callback 
)
pure virtual

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, method, 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 CefServer::SendWebSocketMessage method after receiving the OnWebSocketConnected callback to respond with WebSocket messages.


The documentation for this class was generated from the following file: