Transplantation and application of embedded web server boa

Source: Internet
Author: User

With the development of embedded technology and the popularization of high-speed broadband networks, remote monitoring using networks has been widely accepted. Embedded Network Monitoring Technology has gradually developed and matured under these conditions.

Using a Web browser and remotely accessing the monitoring camera of the built-in web server over Ethernet, users can not only monitor live videos,
The embedded web server plays an important role in the implementation of the entire system. Therefore, in the embedded network video monitoring system, the Web
The server design has a direct impact on the overall performance of the Monitoring System. Only with an efficient Web server can the performance of the monitoring system be fully utilized.

1. Features of Embedded Web Server Boa

Boa is an HTTP server for a single task. Unlike other traditional Web servers, when a connection request arrives,
It does not create a separate process for each connection, nor does it process multiple links by copying its own process. Instead, it creates an HTTP request list to process multiple HTTP connection requests,
At the same time, it only creates new processes for CGI programs, thus saving system resources to the maximum extent, which is crucial for embedded systems.
At the same time, it also has the ability to automatically generate directories and decompress files. Therefore, BOA has high HTTP request processing speed and efficiency, and has high application value in embedded systems.

2 BOA function implementation

The embedded web server boa, like a common web server, can complete tasks such as receiving client requests, analyzing requests, responding to requests, and returning request results to the client. It mainly includes:

(A) initialize the web server, such as creating environment variables, creating TCP sockets, binding ports, starting listening, entering the loop structure, and waiting for receiving connection requests from the client browser;
(B) When a client connects to the request, the web server is responsible for receiving the client request and saving the relevant request information;
(C) After receiving the client connection request, analyze the client request and parse the request method, URL target, optional query information, and form information, at the same time, process the request accordingly;
(D) After the Web server completes the corresponding processing, it sends the response information to the client browser and closes the TCP connection with the client.

The embedded web server boa makes different responses based on different request methods. If the request method is head, it directly returns the response header to the browser;
If the request method is get, the target URL file of the client request is read from the server and sent to the client browser when the response header is returned;
If the request method is post, the form information sent by the customer is sent to the corresponding CGI program, and the CGI program is executed as a CGI parameter,
The function of sending the execution result to the client browser. BOA is also implemented by establishing a connection, binding a port, listening, and request processing.

The source code of the initialization part is as follows:

Int server_s;
Server_s = socket (server_pf, sock_stream, ipproto_tcp );
If (server_s =-1 ){
Die ("unable to create socket ");
}
If (set_nonblock_fd (server_s) =-1 ){
Die ("unable to set server socket to nonblocking ");
}
If (fcntl (server_s, f_setfd, 1) =-1 ){
Die ("can't set close! On! Exec on server socket! ");
}
If (setsockopt (server_s, sol_socket, so_reuseaddr, (void *) & sock_opt,
Sizeof (sock_opt) =-1 ){
Die ("setsockopt ");
}
If (bind_server (server_s, server_ip, server_port) =-1 ){
Die ("unable to bind ");
}
If (Listen (server_s, backlog) =-1 ){
Die ("unable to listen ");
}

The above code is mainly used to open a valid socket Descriptor and convert it to a non-blocking Socket. Function BIND ()
Used to establish the association between the socket Descriptor and the specified port, and listen on the specified port through the listen () function, waiting for a remote connection request. when listening to the connection request, BoA
Call the get_request (INT server_sock) function to obtain the request information. Call the accept () function to establish a connection for the request.
After a connection is established, the system receives the request information and analyzes the request. When there is a CGI request, it creates a process for the CGI program and sends the result to the output through the pipeline. BOA
As shown in figure 1.

3. Port BOA on ARM

3.1 modify the Web server boa

In order to further improve the system performance, appropriate modifications should be made to the web server based on the characteristics of the embedded network video surveillance system. The modifications mainly include:

(A) Define the constant buffer_size as 8192. Increase the value of buffer_size to increase the input/output cache to accelerate image transmission and system response;
(B) modify the request list parameters and modify the number of HTTP connections that the server can process based on the number of possible requests;
(
C) to adapt to a small amount of embedded system resources, streamline library functions in the uCLinux operating system and use uclibc for compilation
Normally running in the embedded system, you must implement some function functions by yourself, such as strstr () and strdup.

3.2 cross-compile Boa

To establish an embedded cross-compilation environment, you must first install the arm-elf-GCC tool, and then use the arm-elf-GCC tool to compile the boa source program by executing:
./Configure-target = arm-elf-host = i686-pc-linux-gnu-build = arm-elf
Make
The executable file BOA in ELF format can be generated.

Use the arm-elf-strip-g boa command to remove the accompanying compilation information to reduce the occupied space.
The file system requires less space than the general ext2 file system. Therefore, the elf2flt tool must be used to generate the executable files of BOA from elf
Convert the format to the flat format and add it to romdisk.

3.3 configure the Web server boa

To run the Web server boa on arm, you need to set the runtime environment and parameters, and set the final configuration file boa. conf.
Place it in the appropriate location. You can configure the Web server by modifying the configuration file boa. conf. Some configurations are as follows: Port 80 is used for listening ports,
Access log accesslog is stored in/var/log/BOA/access_log, Error Log errorlog
The file is located in/var/log/BOA/error_log. the root directory of the file, DocumentRoot, is located in/home/httpd /,
Change the value of keepalivemax to 50, the value of keepalivetimeout to 10, and the value of cgipath to/cgi-bin;
Add servernameemserver at the end of BOA. conf, that is, use emserver as the server name. Of course, use another name as the server name;
Finally, store the modified configuration file boa. conf in the directory of the embedded system root file/etc/boa.
Use the image creation tool to execute the command genromfs-fromfs.img-D romdisk to generate the romdisk image file romfs. IMG,
Download romfs. IMG to flash memory through bootloader.

3.4 test the running of BOA

To ensure the normal running of BOA, use a simple test program to test the running status of BOA. Create the index.html document under/home/httpd/. The content is as follows:
<HTML>
<Body>
This is Boa
</Body>
</Html>
Connect to the embedded system running BOA through the IE browser http: // 192.168.0.26/
If this is boa is displayed on the page, BOA can get the page normally.
Create the test file in the/cgi-bin/path. Its content is:
#! /Bin/sh
Echo Content-Type: text/html
Echo
Echo "<HTML> <body> <PRE>"
Echo "this is CGI test"
Echo "</body> Enter the address http: // 192.168.0.26/cgi-bin/test in the IE browser. If this is CGI test is displayed on the page, the server can normally execute the CGI program.

 4. Application of BOA in the Network Monitoring System

Port BOA to the ARM processor running the uCLinux operating system and establish an embedded web server.
This design scheme can be well applied to the network monitoring system. Because BOA only supports CGI-based dynamic web pages, you need to compile appropriate CGI
The Web server calls the CGI program to monitor the network video and send various commands to the monitoring site.
Based on the actual needs of the monitoring field, the author designs a network video monitoring system based on the above scheme, which can achieve multi-channel video data access, 8
Cloud Platform control and other functions in different directions. Currently, the system has been applied in building monitoring, with good performance and strong real-time performance, as shown in figure 2.

Figure 2 network video monitoring page

5 conclusion

Web servers are an integral part of various network application systems and directly affect the running quality and efficiency of network application systems. BOA
It is designed for embedded systems. Its unique connection processing method and direct calling of the file reading method of the operating system greatly improve the system performance.
Compared with the system resources occupied by the server aparch, the connection processing speed is fast. Using this embedded web server in the network monitoring system can save system resources,
Improve system operation efficiency and give full play to the advantages of the network.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.