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.
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!