Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
  1. This example show how to initialize µC/HTTP-server:
    1. Initialize uC/HTTP-server module objects.
    2. Initialize a web server's instance
    3. Start the web server's instance.
       
  2. This example assumes the presence of µC/TCP-IP and µC/FS. It is assume also that all prerequisite modules have been initialized before starting to initialize µC/HTTP-server and any web server instance.


Code Block
languagecpp
titleListing - Example Code
linenumberstrue
#include  <Server/Source/http-s.h>
#include  <FS/uC-FS-V4/net_fs_v4.h>                             /* See Note #4.                                         */
 
CPU_BOOLEAN  AppHTTPsInit (void)
{
    HTTPs_INSTANCE  *p_https_instance;
    HTTPs_ERR        http_err;


    /*      Prerequisites modules must be initialized prior calling any of the following functions. See Note #1.        */
    /*      Make sure File System (such as uC/FS) is initialized before starting the instance. See Note #2.             */
    /*      Make sure Files that must serve by the web server is loaded in the file system. See Note #2.                */

                                                                /* -------------- INITALIZE HTTPS MODULE -------------- */
    HTTPs_Init(DEF_NULL, &http_err);                            /* See Note #3.                                         */
    if (http_err != HTTPs_ERR_NONE) {
        return (DEF_FAIL);
    }

                                                                /* ---------- INITALIZE WEB SERVER INSTANCE ----------- */
    p_https_instance = HTTPs_InstanceInit(&HTTPs_CfgInstance,     /* Instance configuration. See Note #4a.              */
                                          &HTTPs_TaskCfgInstance, /* Task Instance configuration. See Note #4b.  		*/
                                          &http_err);
    if (http_err != HTTPs_ERR_NONE) {
        return (DEF_FAIL);
    }

                                                                /* ------------ START WEB SERVER INSTANCE ------------- */
    HTTPs_InstanceStart(p_https_instance,                       /* Instance handle. See Note #5.                        */
                       &http_err);
    if (http_err != HTTPs_ERR_NONE) {
        return (DEF_FAIL);
    }
    return (DEF_OK);
}


Panel
bgColor#f0f0f0
  1. Prerequisite modules must be initialized before calling any uC/HTTP-server functions.

  2. Obviously before starting or trying to reach web server. The files must loaded in the file system to be able to get it using an HTTP client.

  3. Prior to do any call to uC/HTTP-server, the module must be initialized. This is done by calling HTTPs_Init(). If the process is successful, the Web server internal data structures are initialized.

    1. The first argument defines the pointer to the memory segment to use by the server to allocate dynamic objects. If set to DEF_NULL the HEAP memory will be used by the HTTP-server stack.

  4. Each web server must be initialized before it can be started or stopped. HTTPs_InstanceInit() is responsible to allocate memory for the instance, initialize internal data structure and create the web server instance's task.

    1. The first argument is the instance configuration, which should be modified following your requirements. The instance configuration set the server's port, the number of connection that can be accepted, the hooks functions, etc.

    2. The second argument is the task instance configuration, which should also be modified following your requirements. 

  5. Once a web server instance is initialized, it can be started using HTTPs_InstanceStart() to become come accessible. This function start the web server instance's task. Each instance has is own task and all accepted connection is processed with this single task.