Class representing a server that supports HTTP and WebSocket requests.
More...
#include "include/cef_server.h"
|
| virtual CefRefPtr< CefTaskRunner > | GetTaskRunner ()=0 |
| | Returns the task runner for the dedicated server thread.
|
| |
| virtual void | Shutdown ()=0 |
| | Stop the server and shut down the dedicated server thread.
|
| |
| virtual bool | IsRunning ()=0 |
| | Returns true if the server is currently running and accepting incoming connections.
|
| |
| virtual CefString | GetAddress ()=0 |
| | Returns the server address including the port number.
|
| |
| virtual bool | HasConnection ()=0 |
| | Returns true if the server currently has a connection.
|
| |
| virtual bool | IsValidConnection (int connection_id)=0 |
| | Returns true if |connection_id| represents a valid connection.
|
| |
| virtual void | SendHttp200Response (int connection_id, const CefString &content_type, const void *data, size_t data_size)=0 |
| | Send an HTTP 200 "OK" response to the connection identified by |connection_id|.
|
| |
| virtual void | SendHttp404Response (int connection_id)=0 |
| | Send an HTTP 404 "Not Found" response to the connection identified by |connection_id|.
|
| |
| virtual void | SendHttp500Response (int connection_id, const CefString &error_message)=0 |
| | Send an HTTP 500 "Internal Server Error" response to the connection identified by |connection_id|.
|
| |
| virtual void | SendHttpResponse (int connection_id, int response_code, const CefString &content_type, int64_t content_length, const HeaderMap &extra_headers)=0 |
| | Send a custom HTTP response to the connection identified by |connection_id|.
|
| |
| virtual void | SendRawData (int connection_id, const void *data, size_t data_size)=0 |
| | Send raw data directly to the connection identified by |connection_id|.
|
| |
| virtual void | CloseConnection (int connection_id)=0 |
| | Close the connection identified by |connection_id|.
|
| |
| virtual void | SendWebSocketMessage (int connection_id, const void *data, size_t data_size)=0 |
| | Send a WebSocket message to the connection identified by |connection_id|.
|
| |
| virtual void | AddRef () const =0 |
| | Called to increment the reference count for the object.
|
| |
| virtual bool | Release () const =0 |
| | Called to decrement the reference count for the object.
|
| |
| virtual bool | HasOneRef () const =0 |
| | Returns true if the reference count is 1.
|
| |
| virtual bool | HasAtLeastOneRef () const =0 |
| | Returns true if the reference count is at least 1.
|
| |
Class representing a server that supports HTTP and WebSocket requests.
Server capacity is limited and is intended to handle only a small number of simultaneous connections (e.g. for communicating between applications on localhost). The methods of this class are safe to call from any thread in the brower process unless otherwise indicated.
◆ HeaderMap
◆ CloseConnection()
| virtual void CefServer::CloseConnection |
( |
int |
connection_id | ) |
|
|
pure virtual |
Close the connection identified by |connection_id|.
See SendHttpResponse documentation for intended usage.
◆ CreateServer()
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 CefServerHandler instance for each CreateServer call to avoid thread safety issues in the CefServerHandler implementation. The CefServerHandler::OnServerCreated method will be called on the dedicated server thread to report success or failure. See CefServerHandler::OnServerCreated documentation for a description of server lifespan.
◆ GetAddress()
Returns the server address including the port number.
◆ GetTaskRunner()
Returns the task runner for the dedicated server thread.
◆ HasConnection()
| virtual bool CefServer::HasConnection |
( |
| ) |
|
|
pure virtual |
Returns true if the server currently has a connection.
This method must be called on the dedicated server thread.
◆ IsRunning()
| virtual bool CefServer::IsRunning |
( |
| ) |
|
|
pure virtual |
Returns true if the server is currently running and accepting incoming connections.
See CefServerHandler::OnServerCreated documentation for a description of server lifespan. This method must be called on the dedicated server thread.
◆ IsValidConnection()
| virtual bool CefServer::IsValidConnection |
( |
int |
connection_id | ) |
|
|
pure virtual |
Returns true if |connection_id| represents a valid connection.
This method must be called on the dedicated server thread.
◆ SendHttp200Response()
| virtual void CefServer::SendHttp200Response |
( |
int |
connection_id, |
|
|
const CefString & |
content_type, |
|
|
const void * |
data, |
|
|
size_t |
data_size |
|
) |
| |
|
pure virtual |
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.
◆ SendHttp404Response()
| virtual void CefServer::SendHttp404Response |
( |
int |
connection_id | ) |
|
|
pure virtual |
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.
◆ SendHttp500Response()
| virtual void CefServer::SendHttp500Response |
( |
int |
connection_id, |
|
|
const CefString & |
error_message |
|
) |
| |
|
pure virtual |
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.
◆ SendHttpResponse()
| virtual void CefServer::SendHttpResponse |
( |
int |
connection_id, |
|
|
int |
response_code, |
|
|
const CefString & |
content_type, |
|
|
int64_t |
content_length, |
|
|
const HeaderMap & |
extra_headers |
|
) |
| |
|
pure virtual |
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 method to send the content, if applicable, and call CloseConnection after all content has been sent.
◆ SendRawData()
| virtual void CefServer::SendRawData |
( |
int |
connection_id, |
|
|
const void * |
data, |
|
|
size_t |
data_size |
|
) |
| |
|
pure virtual |
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.
◆ SendWebSocketMessage()
| virtual void CefServer::SendWebSocketMessage |
( |
int |
connection_id, |
|
|
const void * |
data, |
|
|
size_t |
data_size |
|
) |
| |
|
pure virtual |
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 CefServerHandler::OnWebSocketRequest documentation for intended usage.
◆ Shutdown()
| virtual void CefServer::Shutdown |
( |
| ) |
|
|
pure virtual |
The documentation for this class was generated from the following file: