The object-oriented IO::Socket library significantly simplifies network programming by eliminating much of the "noise code" handed down from the socket API's C heritage and replacing it with a clean and convenient interface. Throughout the remainder of this book we create IO::Socket objects using the class's flexible new() method, and use its object methods whenever they offer a clear syntactic advantage (e.g., $sock->accept() ). In cases where there is no clear syntactic advantage, for example between read ( $sock,$data,1024 ) and $sock->read ( $data,1024 ), we use the Perl built-ins in order to benefit from the performance gains. With the IO::Socket module it is easy to write simple client and server programs, such as the Web client and the reverse echo server demonstrated in this chapter. However, things became unexpectedly complicated when we tried to write a seemingly trivial tool to echo user commands to a server and back again. We solved this by creating two processes using fork() . The struggle against deadlock is a recurring theme in this book, which we deal with again in later chapters. You have now learned how to build network applications on top of the low-level socket libraries. The next part of this book moves up a level, showing you how to interact with application-level protocols. |