Summary

TCP sockets are created using socket(). Clients call connect() to establish an outgoing connection to a remote host. Servers call bind() to assign an address to the socket, listen() to notify the operating system that the socket is ready to accept connections, and accept() to accept an incoming connection. Once a TCP socket is connected, it can be used like a filehandle to read and write stream-oriented data.

Sockets have a number of options that can be set and examined with setsockopt() and getsockopt(), respectively. Unlike filehandles, which when closed allow no further reading or writing, sockets can be half-closed using shutdown(), which allows the socket to be closed for reading, writing, or both.

You've now seen the entire Berkeley ...

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.