NetBurner 3.5.0
PDF Version |
|
Dynamic web content (web content created at run-time) can be created using the following NetBurner HTML tags:
To add a C++ callback we can add a function to main.cpp such as:
And modify index.html to add the tag:
When a web client requests the index.html page, the web server will begin steaming the static content. When it gets to the CPPCALL, it will call the webHelloWorld() function, which will send "Hello World" to the client using the open TCP socket. When the function returns, the web server will continue sending the index.html web page. A web page can have any number of CPPCALL and VARIABLE tags. The parameters passed to the CPPCALL function are the open TCP socket handle, and a pointer to a constant string containing the entire URL of the client web browser. In this way your function can parse the URL if that is important to your application. For example, anything after a '?' character is application specific.
Variables in an application can be displayed on a web page using the VARIABLE tag. This can be useful for displaying information such as time, an IP address, temperature, etc. The format of the tag is:
Where "name" is the name of the application variable or an expression. For example, the system time tick variable TimeTick
can be displayed with
Or you can display the time in seconds with the equation:
The VARIABLE tag is processed during the compilation of the application by parsing the text between <!--VARIABLE
and the trailing -->
and converting it into a function call such as: WriteHtmlVariable( fd, TimeTick/TICKS_PER_SECOND );
In this function fd
is a file descriptor to the current TCP connection to the web client.
Variable types are handled with C++, but you do not need to know anything about C++ to use this feature.
The parameter types are defined by the function definitions located in \nburn\include\htmlfiles.h:
In addition, we have included a class named IPCAST()
that takes a 32-bit value and converts it into an IP address format (e.g. 192.168.1.2). This example will display the IP address in dotted notation, rather than a 32-bit integer:
When an application with web content is built by the NetBurner tools, a file named htmldata.cpp is created. When using the VARIABLE tag for dynamic data, the application must be able to link to the variable. This can be achieved in either of two ways:
htmlvar.h
.
If you need to use a function that can take a parameter, the CPPCALL tag will not work because the parameters are fixed as the socket fd and URL. However, the VARIABLE tag be used for both the function call and variable parameter. The htmlvar.h include file must specify the function definition in one of the formats described in the previous section. the format below. For example, to pass an integer variable webMyInteger in a callback function named webMyFunction:
The HTML file calls the function with:
When the application is compiled the resultant function call will be:
In your .cpp source code the function could look something like this:
The VARIABLE functionality can be extended to support user defined types, such as a user defined structure or class. Lets say you have a structure you want to display on a web page called MySTruct:
In your include file add the function definition: void WriteHtmlVariable(int fd, MY_STRUCT MyStruct);
You then need to implement the function to display the data. For example:
You can then display it on the web page with the VARIABLE tag: