Using IO::Socket

Before we discuss IO::Socket in detail, let's get a feel for it by reimplementing some of the examples from Chapters 3 and 4.

A Daytime Client

The first example is a rewritten version of the daytime service client developed in Chapter 3 (Figure 3.7). As you recall, this client establishes an outgoing connection to a daytime server, reads a line, and exits.

This is a good opportunity to fix a minor bug in the original examples (left there in the interests of not unnecessarily complicating the code). Like many Internet servers, the daytime service terminates its lines with CRLF rather than a single LF as Perl does. Before reading from daytime, we set the end-of-line character to CRLF. Otherwise, the line we read will contain ...

Get Network Programming with Perl now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.