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, You can remotely access the monitoring camera of the built-in web server over Ethernet. This not only enables remote video monitoring on the site, but also sends instructions to the monitoring site. embedded Web servers play an important role in the implementation of the entire system. Therefore, in the embedded network video surveillance system, the Web 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, it does not create a process for each connection when a connection request arrives, instead of copying its own processes to process multiple links, it creates an HTTP request list to process multiple HTTP connection requests. At the same time, it only creates a new process for the CGI program, in this way, system resources are saved 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 receive client requests, analyze requests, respond to requests, and send

The user side returns the request results and other tasks. The work process 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, return the Response Header directly to the browser. If the request method is get, read the URL target file requested by the client from the server while returning the response header, and send it to the client browser. If the request method is post, the form information sent by the customer is sent to the corresponding CGI program and used as the CGI parameter to execute the CGI program, and send the execution result to the client browser. BOA functions are implemented by establishing connections, binding ports, 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. the function BIND () is 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 for a connection request, Boa calls the get_request (INT server_sock) function to obtain the request information and creates a connection for the request by calling the function accept. after a connection is established, the system receives the request information and analyzes the request. when there is a CGI request, create a process for the CGI program and send the result to the output through the pipeline. the overall BOA workflow 1 is shown in.

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 the library functions in the uCLinux operating system and use uclibc for compilation. Therefore, BOA should run properly on 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 compilation information to reduce the occupied space. in uClinux, The romfs file system requires less space than the general ext2 file system. Therefore, the elf2flt tool must be used to convert the executable BOA files from the ELF 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. place conf in the appropriate location. modify the configuration file boa. conf can be used to configure the Web server. Some configurations are as follows: Port 80 is used for listening port, and access log accesslog is stored in/var/log/BOA/access_log, the Error Log errorlog is located at/var/log/BOA/error_log. the root directory of the file, DocumentRoot, is located at/home/httpd/, the value of keepalivemax is changed to 50, and the value of keepalivetimeout is changed to 10, set cgipath to/cgi-bin. add servernameemserver at the end of conf, that is, the emserver is used as the server name, and other names can also be used as the server name. Finally, the modified configuration file boa. conf is stored in the root file/etc/BOA directory of the embedded system. use the image creation tool to execute the command genromfs-fromfs.img-D romdisk to generate the romdisk image file romfs. IMG, set romfs. IMG uses bootloader to download it to flash storage.

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>

Use the IE browser to connect to the embedded system http: // 192.168.0.26/running boa. If this is BOA, 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 to provide users with HTTP-based network access methods, this design scheme can be well applied to the network monitoring system. since BOA only supports CGI-based dynamic web pages, you need to write appropriate CGI programs to send video data and process control commands. web servers call CGI programs to monitor network videos 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. This system can achieve multi-channel video data access and eight-direction cloud platform control functions. at present, the system has been applied in building monitoring, with good performance and strong real-time performance. Its monitoring interface 2 is shown.
 
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 itself is designed for embedded systems. It features connection processing methods and file reading methods that directly call the operating system, greatly improving the system performance. compared with the Web server aparch on Linux, aparch occupies less system resources and supports fast connection. 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.