Example Using Datagram Sockets - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Example Using Datagram Sockets

NOTE
These programs are provided as examples only of datagram socket usage
and are not Hewlett-Packard supported products.
These program examples demonstrate how to set up and use datagram
sockets. These sample programs can be found in the
/usr/lib/demos/networking/socket directory. The client program
is intended to run in conjunction with the server program.
This example implements a simple name server. The server process
receives requests from the client process. It determines the internet
address of the specified host and sends that address to the client process.
If the specified host's internet address is unknown, the server process
returns an address of all 1s.
The client process requests the internet address of a host and receives
the results from the server process.
Before you run the example programs, make the following entry in the
two hosts /etc/services files:
example
The source code for these two programs follows.
/*
*
* This is an example program that demonstrates the use of
* datagram sockets as an BSD Sockets mechanism.
* the server, and is intended to operate in conjunction with the
* client program found in client.udp. Together, these two
* programs demonstrate many of the features of sockets, as well
* a good conventions for using these features. NOTE: This example
* is valid only if the /etc/hosts file is being used to lookup
* host names.
*
* This program provides a service called "example".
* example of a simple name server.
* it to function, an entry for it needs to exist in the
* /etc/services file.
* any port number that is likely to be unused, such as 22375,
* for example.
The host on which the client will be running
* must also have the same entry (same port number) in its
* /etc/services file.
*
*/
#include <sys/types.h>
Chapter 4
22375/udp
S E R V . U D P
In order for
The port address for this service can be
Using Internet Datagram Sockets
Example Using Datagram Sockets
This contains
It is an
101

Advertisement

Table of Contents
loading

Table of Contents