Simple DNS Lookups
Being an FTP Client
Reading and Posting Usenet News Messages
Reading Mail with POP3
Simulating Telnet from a Program
Pinging a Machine
Using Whois to Retrieve Information from the InterNIC
Program: expn and vrfy
This "telephone" has too many shortcomings to be seriously considered as a means of communication. The device is inherently of no value to us.
- - Western Union internal memo, 1876
Correct use of sockets is only part of network communicating programs. Once you have a way for two programs to talk, you still need a protocol for communication. This protocol lets each party know when to talk, and it precisely defines who is responsible for which part of the service.
File Transfer Protocol
Copying files between remote machines
rsh and rcp
Remote shell and Remote copy
Remote login and remote file copying
Reading and posting USENET news
Hypertext Transfer Protocol
Transferring documents on the Web
Simple Mail Transfer Protocol
Post Office Protocol
Even something as relatively simple as connecting to a remote computer requires intricate negotiations between client and server and has numerous dynamically configurable options. If you had to write the Perl code to implement these protocols each time you wanted to use a network service, you'd probably end up writing a lot of buggy programs, try to get demoted into a management position, or both.
Fortunately, CPAN has modules for these protocols. Most modules implement the client side of the protocol rather than the server side. This means your program can use these modules to send mail, but not to be a mail server that other clients connect to; to read and post news, but not be a news server that other clients connect to; to transfer files to and from an FTP server, but not to be an FTP server that other clients connect to; and so on.
Most of these modules fall under the Net:: hierarchy. We'll be using Net::FTP to send and receive files using FTP, Net::NNTP to read and post Usenet news, Net::Telnet to simulate a connection to another machine, Net::Whois to find out information about a domain name, Net::Ping to check whether a machine is alive, and Net::POP3 and Mail::Mailer to receive and send mail. We deal with the CGI protocol in Chapter 19, CGI Programming, and HTTP in Chapter 20, Web Automation.
You can thank Graham Barr for most of these modules, whose IO::Socket modules we used for low-level network communication in Chapter 17, Sockets. He wrote Net::FTP, Net::NNTP, Net::POP3, and Mail::Mailer. Jay Rogers wrote Net::Telnet, and Chip Salzenberg wrote Net::Whois. Thank these folks that you don't have to reinvent these tricky wheels!