NetworkWebServerInterface Class Reference

#include <network_webserver.h>

Inheritance diagram for NetworkWebServerInterface:

详细描述

Easy interface to create and start a web server and handling http requests. The web server starts several threads that handles the requests. So make sure that you keep the handle as long as the server is running.

公共成员函数

MAXON_METHOD Result < void >  Init ( Bool useSSL, const NetworkIpAddrPort &serverIpAndPort, const String &serverName)
MAXON_METHOD Int   GetServerPort () const
MAXON_METHOD String   GetServerName () const
MAXON_METHOD Bool   IsUsingSSL () const
MAXON_METHOD Result < void >  StartServer ( Bool waitForListener)
MAXON_METHOD Result < void >  StopServer ()
MAXON_METHOD Result < void >  RegisterRequest (const String &file, HandleRequestDelegate &&requestDelegate)
  MAXON_OBSERVABLE ( Result < void >, ObservableHandleRequest,(const NetworkWebServerRef &server, const NetworkHttpHandlerRef &remoteConnection, const DataDictionary &request), CombinerHttpCodeComponents)

私有成员函数

  MAXON_INTERFACE ( NetworkWebServerInterface , MAXON_REFERENCE_NORMAL , "net.maxon.interface.networkwebserver")

成员函数文档编制

◆  MAXON_INTERFACE()

MAXON_INTERFACE ( NetworkWebServerInterface   ,
MAXON_REFERENCE_NORMAL   ,
"net.maxon.interface.networkwebserver"   
)
private

◆  Init()

MAXON_METHOD Result <void> Init ( Bool   useSSL ,
const NetworkIpAddrPort serverIpAndPort ,
const String serverName  
)

Init initializes the web server object and tells which port should be used.

参数
[in] useSSL Should the server use SSL/TLS?
[in] serverIpAndPort Server ip and port. If addr is 0.0.0.0 the server will be bound to all interfaces. If serverPort is 0, the system chooses an port. Otherwise the port needs to be in the range 0 < port < 10000.
[in] serverName Name of the server (only 'a..z''A..Z' are valid).
返回
OK on success.

◆  GetServerPort()

MAXON_METHOD Int GetServerPort ( ) const

Returns the server port. If 0 was given at Init() the serverport is only available after starting the server.

◆  GetServerName()

MAXON_METHOD String GetServerName ( ) const

Returns the server name.

◆  IsUsingSSL()

MAXON_METHOD Bool IsUsingSSL ( ) const

Returns whether the server uses the SSL/TLS protocol.

◆  StartServer()

MAXON_METHOD Result <void> StartServer ( Bool   waitForListener )

Starts the web server.

参数
[in] waitForListener If true the functions waits until the listener is open. Otherwise it returns immediately.
返回
True if the functions was successful.

◆  StopServer()

MAXON_METHOD Result <void> StopServer ( )

Stops the web server.

返回
True if the functions was successful.

◆  RegisterRequest()

MAXON_METHOD Result <void> RegisterRequest ( const String file ,
HandleRequestDelegate &&  requestDelegate  
)

RegisterRequest allows to add callback delegates to handle urls. If the handler returns "HttpCodeError(MAXON_SOURCE_LOCATION, HTTPCODE::CALL_NEXT_HANDLER)" the next handler is called.

参数
[in] file Url to catch. if the string ends with a "*" the pattern will be matched.
[in] requestDelegate Delegate to call.
返回
OK on success.

◆  MAXON_OBSERVABLE()

MAXON_OBSERVABLE ( Result < void >  ,
ObservableHandleRequest  ,
(const NetworkWebServerRef &server, const NetworkHttpHandlerRef &remoteConnection, const DataDictionary &request)  ,
CombinerHttpCodeComponents   
)

ObservableHandleRequest is fired as soon as a client connects to the server. For each connection a new thread is spawned.

参数
[in] server Reference to the server object.
[in] remoteConnection Reference to the remote connection. This handle allows to read and write from the ip stream.
[in] request The pre-translated http request from the server. See HTTPREQUEST for details. Predefined values can be found under it's id. All unknown header informations can be found under a string as the key of the dictionary. Try DiagnosticOutput("@", request); to see all members of the dictionary.
返回
返回 HTTPCODE::FINISHED if the request has been successfully replied. Return HTTPCODE::CALL_NEXT_HANDLER to call the next handler in the queue. Return a error code to respond with the error code.