SDSU CS 596: Client Server Programming
Libc and Library APIs

San Diego State University -- This page last updated March 30, 1995

Table of Contents


Hints for Assigments

Standard C Library routines

Look at online man pages

Locating commands or functions:

apropos <word>

orman -k <word>

Specifying a section

Example: write(2)

Saturn: man 2 write

Rohan: man -s 2 write


Using xinetd instead of inetd

NOTE: xinetd is only installed on saturn.

inetd requires all services to be listed in /etc/services

xinetd allows unlisted services

Sample configuration file:

service fortune
{
    type = UNLISTED
    port = <yourport>    socket_type = stream
    protocol = tcp
    wait = no
    service = <server and args>}

Replace <yourport> with your UID and replace <server and args> with the path to your fortuned program and any arguments.


Xinetd

Start xinetd as follows:xinetd -d -f <configfile>

where <configfile> is the file which contains the xinetd configuration.

Reference the following man pages:

Important: Always run xinetd with the -d flag.


Library APIs

(API == Application Programming Interface)

What is an API?

Why do we need/want APIs?


Examples of existing APIs


Detailed example

Original purpose of rplay:

Requirements:


rplayd -- rplay server

rplay uses IPC.

The server, rplayd, can reside on any machine.

rplayd supports two protocols:

rplayd:


rplay protocol

Uses UDP

sounds are identified by name

rplay clients only need to send over the name of the sound in a rplay packet.

In a game situation there can potentially be thousands of sounds played.

Since the sounds are non-critical, UDP packet loss is not a major concern.


rptp

Uses TCP

Designed to be used by intelligent clients but also humans.

Allows sending and receiving of actual sound files

Can asynchronously notify a client about a given set of events.

Everything that can be done with the rplay protocol can be done with rptp.


rplay protocol API

rplay packets can have several sound names

Each sound name has attributes associated with it (name, volume, priority, spool id)

Sequence of calls for a client using rplay:


Example code using librplay

opening a "connection"

int rplay_fd = rplay_open("hercules");
if (rplay_fd < 0) {
    rplay_perror("rplay_open");
    exit(1);
}

Creating an rplay packet

RPLAY *rp = rplay_create(RPLAY_PLAY);
if (rp == NULL) {
    rplay_perror("rplay_create");
    exit(1);
}

Setting attributes in a packet

rplay_set(rp, RPLAY_APPEND,
          RPLAY_SOUND, "bogus.au",
          RPLAY_VOLUME, 200,
          NULL);

Example code using librplay (continued)

Playing a sound

if (rplay(rplay_fd, rp) < 0) {
    rplay_perror("rplay");
    exit(1);
}

Things to note about the design

a rplay packet only needs to be created once

rplay_set (and also rplay_get) use attribute lists

Other attributes are: