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 socket API. The next chapter introduces Perl's object-oriented extensions, which greatly simplify the task of working with sockets. |