Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Perl CGl Programming: No experience required.
(Publisher: Sybex, Inc.)
Author(s): Erik Strom
ISBN: 0782121578
Publication Date: 11/01/97

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using TCP/IP and the hosts file

The Sambar server runs on Windows 95 and NT. However, it also requires that TCP/IP, the Internet communication protocol we discussed in Skill 1, is running on its host computer. If you’re not familiar with the term TCP/IP, you probably don’t have anything to worry about because even the lowliest dial-up connection to an Internet service provider requires it. So if you can get out to the World Wide Web, you certainly have TCP/IP running on your computer already.

You can take advantage of a handy TCP/IP feature to use any Web browser to connect directly with the Sambar server on your computer: the hosts file.

When you type a URL into your Web browser it is usually in the form of an Internet domain address such as www.WebSite.com. But the descriptive address is meaningless to the software that routes information around the Internet. The address has to be translated into an IP address such as 198.169.20.0 before anything can be done with it.

Normally, the browser gets that information from a Domain Name Server (DNS), which runs on the ISP’s computer. In a very simple sense, the DNS is a table of domain names and IP addresses; the browser gives it a name, and the DNS returns the numeric address.

If your computer isn’t hooked up to your ISP, the Web browser has no way to resolve domain names. However, in the TCP/IP scheme of things, the DNS is the second place to look for addresses. The first is the hosts file, which is right on your computer (see Figure 2.12).


Figure 2.12:  The default hosts file on Windows NT

The hosts file is a plain text file; you can call it up with any text editor, such as Notepad. On Windows 95, the file is in the \Windows directory. On Windows NT, you will find it in \winnt\system32\drivers\etc.

As in Perl, lines in the hosts file that begin with the pound sign (#) are comments. Notice in Figure 2.13 that the only uncommented line in the file is the last one:

   127.0.0.1    localhost

The line illustrates how IP addresses are associated with domain names in the hosts file. This particular IP address (127.0.0.1) is special, however. It defines a loopback address that always points to the local computer. It is usually used for testing and, in fact, that’s how you will use it.

You should ensure that you actually have a hosts file by using Explorer to poke into the appropriate directory for your operating system. If you don’t see the file, it’s easy enough to create it by following these steps:

1.  Open your favorite text editor.
2.  Type in 127.0.0.1.
3.  Press the space bar a few times or the Tab key twice.
4.  Type in localhost.
5.  Press [return].
6.  Save the file as \windows\hosts on Windows 95 or \winnt\system32\ drivers\etc\hosts on Windows NT.

Now, if the Sambar server is running, you can point your Web browser to http://localhost and the server’s default home page will pop up.

By the way, although you should have one entry in the hosts file that associates 127.0.0.1 with the name localhost, you’re not stuck with that one name. Any domain name that you put on the same line will be linked with the IP address, so you could type:

   127.0.0.1    localhost www.alfredpacker.com mydomain.com

Now www.alfredpacker.com and mydomain.com point to the same address as localhost and you can use them as URLs in your Web browser.


WARNING:  Remember that IP address resolution is attempted first in the hosts file and then on your ISP’s Domain Name Server. If you point a real Internet domain name to the localhost address, you will never be able to get to it over the Internet, because TCP/IP will find it linked with 127.0.0.1 in the hosts file and will look no farther.

Running the Sambar Server

The default Sambar Web server installation will put a shortcut to the software in your Programs menu. All you have to do to start the server is open the Programs menu and click the shortcut. You will notice first of all that nothing seems to happen. Not to worry—the server runs in the background. The only evidence of its presence is a small icon on the right side of the Taskbar.


EXERCISE:  The Sambar Server: Building Your Web Site

This is the first of a series of exercises—relating specifically to the Sambar server—that you will find here and at the end of the subsequent skills in this book. Follow along to get some ideas about building your Web site from the ground up.

  Open your Web browser and point it to http://localhost or any other domain name you have linked to the loopback address.
  The default Sambar server home page will pop up. Look at it, try out some of its features, read the instructions. (Remember that if you aren’t hooked up to the Internet, some of the page’s domain-search and lookup features won’t work.) In the next skill, you’ll substitute your own home page for the Sambar default page.
  Connect to the Internet (if you aren’t already connected) and point your Web browser’s news reader to comp.lang .perl. If you ever have questions about how Perl works, you can find the answers somewhere in this newsgroup.

Moving On

You’ve learned a bit about setting up your Web server in this skill, and you have begun your acquaintance with the Perl-HTML connection. You have also learned about using subroutines in Perl to produce reusable code.

In Skill 3, you’ll be introduced to the Common Gateway Interface and the environment variables that you can use to hook the Web server to a Perl script. You’ll learn several new and useful concepts in Perl, as well.

Are You Experienced?

Now you can…

  write a Perl program that draws an HTML document in a Web browser through CGI
  configure your Web server to run Perl and place your CGI programs where the server expects them to be
  write and call Perl subroutines
  understand the basics of the interaction between CGI and the HTTP/HTML combination
  understand the basics of the MIME standard and how it defines the rules of Web communication


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.