The sample programs shown here were tested on Sun workstations running SunOS 4.1.3 and SunOS 5.3. These programs are examples of stream sockets for the UNIX and Internet domains. Although datagrams (UDP) are supported, they are unreliable and delivery of packets is not guaranteed. They are used in the Internet domain by programs such as rwho and ruptime but are rarely used in the UNIX domain.
The following scripts are very simple examples of the client/server model utilizing stream sockets for communication endpoints. Both client and server reside on the same machine, and the client simply reads a greetings message from the server and prints the message on the screen. There is little error checking or signal handling. The programs are simple demonstrations of how those socket functions are used. (For socket functions not included in this chapter, see Table A.1 in Appendix A.)
The following program was executed on two Sun workstations. The server's hostname is scarecrow, running SunOS 5.3, and the client's hostname is houston, running SunOS 4.1.3. In this program, the client on one machine asks the server on another machine for the time. The server sends the time to the client socket, and the client prints the time in readable format to the screen. These examples do not take advantage of Perl 5's Socket.pm module in the standard library. All values are hardcoded and therefore are not necessarily portable from one machine to another. (See "The Socket.pm Module" on page 808.)