In: Categories » » Ethernet » Serving Web Pages with Dynamic Data
Because embedded systems almost always serve Web pages that contain dynamic, or real-time, information, this networking tutorial begins with Rabbit and TINI examples that serve Web pages with dynamic content. Following the examples is an introduction to using HTTP and other protocols in serving Web pages.
Two Approaches
A Web browser such as Microsoft’s Internet Explorer is a client application that uses HTTP to request Web pages from servers on the Internet or in a local network. The servers don’t have to be PCs or other large computers. Even a small embedded system with limited memory can serve a page containing text and simple images, including pages that display real-time data and accept and act on user input. A browser provides a user interface for requesting and displaying pages. The computers that request Web pages typically have full-screen displays, but for some applications, an embedded system with limited display capabilities can function as an HTTP client. If the requested pages are very simple, even a text-only display of a few lines might suffice. Or an embedded system might receive and process the contents of a Web page without displaying the page in a browser at all. This networking tutorial focuses on Web servers. With an Internet connection, a Web server can serve pages to any browser on the Internet. Or a server may be programmed to respond to requests only from specific IP addresses. A Web server in a local network may serve pages to selected computers or to any computer in the local network.
An embedded system that functions as a Web server generally has all of the following:
• Non-volatile memory to hold pages to be served.
• Support for TCP and IP. Requests for Web pages and the pages sent in response travel in the data portion of TCP segments.
• Support for HTTP. The server must be able to understand and respond to received requests for Web pages. The HTTP standard specifies the format for the requests and replies.
• A local-network or Internet connection. To serve pages on the Internet, the Web server must have an Internet connection. Any firewalls must be configured so the system can receive HTTP requests, as described in Chapter 10.
• One or more pages to serve. The Web pages are files or blocks of text that use a form of encoding called hypertext markup language (HTML).
The HTML encoding specifies the formatting of text and images on the page, including text size and fonts and the positioning of text and other elements on the page. The HTML code may include links to images that appear on the page, as well as links to other pages or resources. In serving a Web page with dynamic content, the software must have a way of inserting the dynamic content as the page is being served. A variety of protocols and technologies can work along with HTTP and HTML to enable a server to provide Web pages that contain real-time data and respond to user input. This networking tutorial includes two approaches to serving real-time data, and Chapter 7 covers ways that Web servers can respond to user input.
Serving a Page with Dynamic Data
Many Web pages are static, where the information on the page doesn’t change unless someone edits the page’s HTML file and uploads the new file to the server. Static Web pages are useful for presenting product information, articles, or other information that remains constant. But most embedded systems have little use for static pages, other than possibly presenting a home page with links to other pages. An embedded system that functions as a Web server will almost certainly want to display real-time information such as sensor readings or other up-to-the-minute information about the processes or environments the system is controlling or monitoring.
This section shows how the Rabbit and TINI modules introduced in Chapter 3 can serve Web pages that display dynamic data. Dynamic, or real-time, data includes any data that can change over time and can be different each time the page is served. An obvious example is a counter that displays the number of times the page has been accessed. Dynamic data may also include sensor or switch readings and time and date information. The supporting code included with the Rabbit and TINI (and additional sources in the case of Java servlets on the TINI) greatly reduces the amount of the programming required to serve Web pages with dynamic content. The dynamic data served by the example applications in this networking tutorial consists of a message that displays the amount of time the system or application has been up and running. Network article 6-1 shows an example page. The embedded system stores the number of days, hours, minutes, and seconds in variables. When serving the page, the server application inserts the current values of the variables in the appropriate places in the page. You can use the same techniques to create Web pages that display the current values of any variables in a system. Although the result is the same, the Rabbit and TINI examples use different approaches to achieve the result. The Rabbit uses Server Side Include directives that instruct the server to insert the values of variables in the appropriate locations in the file being served. For the TINI, instead of storing the Web page in a separate file, the application creates the Web page as it’s being sent, using a series of writes to send the page’s contents to a TCP socket and inserting the values of variables in the designated locations in the page.
legal notice
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
Useful tools and features
related articles
NE2000 Compatibility A term you’re likely to hear in reference to program code for network controllers is NE2000-compatible. The NE2000 was an early and popular PC network interface card from Novell. The card contained National Semiconductor’s DP8390 controller. Software for systems that use the ’8390 or a compatible chip has come to be known as NE2000-compatible code. A major feature of the ’8390 is its set of internal registers. By reading and writing to the registers, a CPU can c...
2. Using the Internet Protocol in Local and Internet Communications
The protocols in the IEEE 802.3 Ethernet standard enable the computers in a local network to exchange messages with each other. In practice, most Ethernet networks also use Internet protocols such as TCP or UDP and IP. These provide defined and well-supported methods for accomplishing common tasks such as flow control and flexible addressing and routing of messages. Messages that travel on the Internet must use IP. And because TCP and UDP are designed to work along with IP, local communications that use TCP or UDP also use...
3. There are several options for obtaining an Internet connection
Technologies for Connecting There are several options for obtaining an Internet connection. A long-popular way for home users to connect to the Internet is via dial-up connections on phone lines. For higher speeds, alternatives are a Digital Subscriber Line (DSL), an Integrated Services Digital Network (ISDN) line, or a cable modem. Satellite connections are also possible. Table 4-1 compares the capabilities of the different methods. Not every connection type is available in all locations. Depending on ...
4. Every computer that communicates over the Internet must have an IP address
Static and Dynamic IP Addresses Every computer that communicates over the Internet must have an IP address, which the computer typically receives from its ISP. The IP address may be static or dynamic. A static IP address stays the same until someone explicitly changes it, while a dynamic IP address can change on every boot up or network connect (though the address typically changes only occasionally). An embedded system may store a static IP address in non-volatile memory, either within an application...
5. Obtaining and Using a Domain Name
Obtaining and Using a Domain Name After you obtain Internet access, connect your embedded system to the Internet, and configure your firewall to enable the embedded system to communicate, the system is ready to send and receive messages on the Internet. Applications running on other computers on the Internet can access the embedded system by specifying its public IP address. For example, to view a server’s home page, in the Address text box of a Web browser, you enter http:// followed by the server&rsquo...
6. Inside the Internet Protocol
The Internet Protocol (IP) helps data find its way to its destination even if the data must travel through other networks, including the many and varied networks that make up the Internet. Although it’s called the Internet Protocol, local networks can use IP as well. Many communications in local networks use IP because they use its companion protocols, TCP and UDP. This section introduces IP, including how computers obtain IP addresses, the format of IP datagrams, how IP and the domain name system help in getti...
7. A computer that uses the Internet Protocol must have an IP address
IP Addresses A computer that uses the Internet Protocol must have an IP address. A network administrator may manually assign an IP address to each computer or the network may have a way of assigning addresses automatically to computers that connect to the network. An IPv4 address is 32 bits. As explained earlier in this networking tutorial, the conventional way to express an IP address is in dotted-quad format, such as 192.168.111.1. Assigning Addresses Each IP datagram includes t...
8. With classless addressing the network address and IP prefix
Classless Addressing With classless addressing, the network address and IP prefix are often expressed in the form: xxx.xxx.xxx.xxx/n where xxx.xxx.xxx.xxx is the lowest IP address in the network and n is the number of bits in the network-address portion of the IP address. For example, with a network address and IP prefix of 192.0.2.0/24, the network address is 192.0.2 (three bytes, or 24 bits), and the final eight bits in the IP address are the host address. In routing datagrams for addresses that us...
9. Considerations when Using Dynamic IP Addresses
Dynamic Allocation One thing that automatic allocation doesn’t define is a way to reclaim addresses that are no longer in use. Reclaiming addresses is essential in networks that have more potential hosts than available IP addresses. For example, the hosts connected to an ISP at any one time will vary as different customers go on and off line. If the ISP assigns a permanent, or static, address to every computer that connects, it will eventually run out of addresses, even if only a few customers connec...
10. Hosts that support IP must also support the ICMP
The Internet Control Message Protocol (ICMP) Hosts that support IP must also support the Internet Control Message Protocol (ICMP) defined by RFC 792: Internet Control Message Protocol. ICMP is a basic protocol for sending messages. Some common uses for ICMP are to send a PING message to learn if a host is available on the network and to obtain the IP addresses of local routers. ICMP messages travel in IP datagrams. The Protocol field in the IP header is 1 to indicate ICMP. The first byte in the data portion of...
