HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 48
Example Using Internet Stream Sockets
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 48 highlights
NOTE Using Internet Stream Sockets Example Using Internet Stream Sockets Example Using Internet Stream Sockets These programs are provided as examples only of stream socket usage and are not Hewlett-Packard supported products. These program examples demonstrate how to set up and use internet stream sockets. These sample programs are in the /usr/lib/demos/networking/socket directory. The client program is intended to run in conjunction with the server program. The client program requests a service called example from the server program. The server process receives requests from the remote client process, handles the request and returns the results to the client process. Note that the server: • Uses the wildcard address for the listen socket. • Uses the ntohs address conversion call to show porting to a host that requires it. • Uses the SO_LINGER option for a graceful disconnect. The client process creates a connection, sends requests to the server process and receives the results from the server process. Note that the client: • Uses shutdown to indicate that it is done sending requests. • Uses getsockname to see what socket address was assigned to the local socket by the host. • Uses the ntohs address conversion call to show porting to a host that requires it. Before you run the example programs, make the following entry in the two host's /etc/services files: example 22375/tcp The source code for these two programs follows /* * S E R V . T C P * * This is an example program that demonstrates the use of stream * sockets as a BSD Sockets mechanism. This contains the server, * and is intended to operate in conjunction with the client * program found in client.tcp. Together, these two programs 48 Chapter 2