Getting Started with the G Web Server (LabVIEW Internet Toolkit)
Overview
The LabVIEW Internet Toolkit includes the G Web Server, which is an HTTP/1.0-compatible server that you can use to run applications on the Web. This topic provides a step-by-step introduction to configuring and running the G Web Server.
(Windows) In LabVIEW 8.6 and later, you also can use LabVIEW Web services and the LabVIEW Web server to run applications on the Web.
The G Web Server is a stand-alone VI that runs independently of other VIs that are running. The G Web Server can perform the following tasks with VIs:
- Run VIs—You can use the G Web Server to load and run VIs that you create using the Internet Toolkit CGI VIs. You can run VIs on the Web without using a plug-in or run-time engine.
- Work with CGI applications—You can use CGI applications to create documents whose content frequently changes and to process queries and form requests. CGI applications run on HTTP servers and are different from applets you download and execute on client computers.
- Integrate with other computers—You can run the G Web Server on a development computer or integrate it into a stand-alone application.
- Work on different platforms—You can run the G Web Server on all platforms that work with LabVIEW version 7.0 or later. The CGI VIs that you use on any of these platforms run on any of the other platforms.
- Implement security—You can limit access by directory or by VI name. You can control access by the client address, the referring document, or through group and password files.
- Publish front panel images—You can use the G Web Server to publish the front panel of any VI in memory to the Web as a static or an animated image.
Configuring the G Web Server
To ensure the G Web Server runs correctly, you must set appropriate configuration options. Complete the following steps to configure the G Web Server.
- Select Tools»Internet»G Web Server Configuration. The G Web Server Configuration dialog box appears.
- On the Operation tab, determine if you want to run the G Web Server in independent mode or in shared-port mode, as shown in the following dialog box.

In independent mode, the G Web Server runs on a port different from the one on which the LabVIEW Web Server runs. In shared-port mode, the G Web Server shares a port with the LabVIEW Web Server and handles only CGI requests, while the LabVIEW Web Server handles other requests.
Note: In LabVIEW 8.6 and later, the G Web Server cannot share a port with the LabVIEW Web Server. If you have applications that include both Internet Toolkit CGI VIs and LabVIEW remote panels, the VIs and the remote panels cannot be on the same port. You must reimplement the CGI VIs using the LabVIEW Import Web Service wizard.
- Notice the Port text box, which specifies the TCP/IP port that the server is using. The default for HTTP is port 80. You might have to specify a different port if another HTTP server, including the LabVIEW Web Server, is already using port 80 on the computer or if you do not have permission to use reserved ports. If you use a non-default port, such as 8000, you must specify it on URLs that refer to the server, such as http://hostname:8000/index.htm, where hostname is the computer name.
- In the Document Root text box, specify the directory that contains the HTML document you want as the root or home page document. The default is the www directory, which contains the example home directory that the Internet Toolkit installs.
- Click the Advanced tab. In the Server Admin text box, enter the email address you want to use. If the G Web Server encounters an error while retrieving a document, the server generates a document with the email address so viewers of the pages can alert you to the problem.
- Remove the checkmark from the Use DNS checkbox if you do not have access to a DNS server. When you place a checkmark in the Use DNS checkbox, the server converts TCP/IP addresses, such as 130.164.140.14, to their corresponding hostnames, such as www.ni.com. If you do not have access to a DNS server, looking up the name fails and significantly slows down the performance of the server.
- Click the Save button to save the configuration settings.
- Click the Done button to close the dialog box.
Note: If you want to set configuration options other than those in the G Web Server Configuration dialog box, you must open the configuration file in a text editor to edit the options manually. The access configuration, server configuration, and server resource map configuration files are located in the internet\http\conf directory. Refer to the LabVIEW Help for more information about specific configuration files and directives.
Running the G Web Server
Complete the following steps to run the G Web Server so you can examine its features.
- Select Tools»Internet»Start G Web Server. The G Web Server window opens.
Tip: You also can run the G Web Server from the Advanced tab of the G Web Server Configuration dialog box. Click the Start the G Web Server button.
The TCP/IP hostname of the computer and the port you are using appear in the G Web Server window. You can view the G Web Server window in simple mode or detailed mode. The default is simple mode, shown in the following example, which uses less screen space and fewer system resources.

[+] Enlarge Image
Refer to the Displaying the G Web Server Window in Detailed Mode section for information about viewing the G Web Server window in detailed mode. - Open a Web browser so you can experiment with the G Web Server.
- Type the following string in the URL field of the Web browser:
hostname/.snap?HTTP+Server
Replace hostname with the name of the computer you are using, as displayed on the G Web Server window. If the hostname does not appear on the window, replace hostname with the word localhost or 127.0.0.1, which is the IP address for the local host. A screenshot or animated image of the G Web Server window appears.
In this example, the plus sign (+) replaces the whitespace in the name of the VI because a URL cannot contain spaces. You also can replace special characters with their hexadecimal value preceded by a percent (%) sign. For example, you would use %20 for whitespace because 20 is the hexadecimal ASCII value of the space character. Otherwise, the name of the VI you observe should match the name in the VI menu bar. Each time you retype the URL or click the Reload or Refresh button on the browser, you can see a new image of the specified VI front panel.
Note: URLs are not case sensitive. However, you must include filename extensions as part of the URL.
Viewing Online Examples
You can learn about the capabilities of the G Web Server by examining the online examples that the Internet Toolkit includes. Complete the following steps to access the default example Web page.
- In the URL field of the Web browser, type the computer hostname, localhost, or 127.0.0.1. The G Web Server Web page should appear. If you see something else, you must configure the document root directory properly. Refer to the Configuring the G Web Server section for more information about configuring the G Web Server.
Note: To access the default example Web page when you are in shared-port mode, you must include http://localhost/indexcgi.htm in the URL field.
- Click the View CGI Examples button to view a list of examples of G Web Server features. The examples demonstrate form processing through CGI VIs, static and animated panel images, password protection, and cookies.
To understand how the online examples work, you should be familiar with HTML code. To examine the HTML code for an example, select View»Source from the browser menu bar and search for the link, form element, or other feature that interests you. Many built-in examples invoke CGI VIs, for which the HREF for the link contains a VI name.
Examining Online CGI Examples
The Internet Toolkit includes online examples that you can access from the G Web Server home page. These examples demonstrate how you can use LabVIEW to create CGI applications that perform tasks over Web pages.
Complete the following steps to view an online example of a VI that uses CGI VIs.
- From the G Web Server home page, click the View CGI Examples button.
- Click the CGI Basics link.
- Click the CGI Call with Multiple Parameters (POST) link to open the example.
- Click the Submit button under the form to invoke the post_mlt VI, which uses the values of the form elements you selected to create an HTML document with a table that summarizes the values. The post_mlt VI is an example VI that contains CGI VIs as subVIs.
You can observe how an online example VI relates with a link or a Submit button by examining the HTML code for the example page. If you want to view the block diagrams of online example VIs, the VIs are located in the www\cgi-bin\examples directory. The following illustration displays the block diagram of the post_mlt VI.
The CGI VIs that the post_mlt VI contains are subVIs that you must include in every CGI-related VI you create. The CGI Read Request VI obtains content strings that the client submits and provides that information to the rest of the block diagram in the form of a keyed array and a string. The CGI Write Reply VI sends a response to the client to display in the browser. Typically, this response comes in the form of HTML or a reference to an existing URL. The CGI Release VI frees the resources associated with this particular CGI call.
The CGI VIs in the post_mlt VI are specific to decoding the form elements that the CGI application received in this example using the POST method. These VIs are specific to building an HTML table to return to the client browser. Refer to the LabVIEW Help for more information about specific CGI VIs.
Displaying the G Web Server Window in Detailed Mode
The G Web Server window displays the G Web Server status information. You can view the window in simple mode or detailed mode. Click the black triangle next to the server name to switch the G Web Server window from simple mode to detailed mode, as shown in the following example.
In detailed mode, the G Web Server window displays the information from simple mode along with the following information:
- Server Activity—Displays information about different server aspectsWhen you select an item in the list, the text box on the right displays detailed information. You can select the following items:
- Pending Connections—Indicates the number of connections that the server has accepted but not processed. Select this item to display addresses of the connections.
- Active Connections—Indicates the number of open connections. Select this item to display addresses and requests of the connections.
- Server Push Connections—Indicates the number of current server-push, or image animation, connections. Select this item to display addresses and requests of the server-push connections.
- Cached CGIs—Indicates the number of CGI VIs currently in memory. Select this item to list CGI VI names, activity status, and the number of pending requests for each CGI VI.
- Active CGIs—Indicates the number of CGI VIs currently processing requests.
- Log—Displays the most recent server requests and server error messages. Each request line consists of the date, time, remote system address, username or the symbol (-), and the request that the client sent. Error lines depend on the error condition, such as an invalid URL.
You can find more complete log information in the server log files, located in the internet\http\logs directory.
Using CGI VIs with the G Web Server
Servers and CGI applications communicate through environmental variables and through standard inputs and outputs. When an HTTP server executes a CGI application, it sends information using environmental variables. Refer to the LabVIEW Help for a list of environmental variables that LabVIEW supports.
Because LabVIEW does not work with standard HTTP input and output, a CGI VI receives the standard input data as a string when it receives a request and sends data that it generates as a string.
Publishing Front Panel Images with the G Web Server
You can use the G Web Server to publish images of front panels on the Web. You do not need to modify VIs to display images of their front panels. You can load static or animated front panel images. The G Web Server can generate images in JPEG or PNG image formats.
You can use the .snap, .monitor, and .spool URLs to publish images. If you use the G Web Server in shared-port mode, the LabVIEW Web Server handles .snap and .monitor requests and the G Web Server handles .spool requests. Refer to the LabVIEW Help for more information about publishing front panels to the Web.
Note: Currently, only Netscape supports animated images of the front panel. Internet Explorer 5.0 or later does not support animated images, but it does periodically refresh the screen.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).


