SDSU CS 596 Client-Server Programming
Network Services

[To Lecture Notes Index]
San Diego State University -- This page last updated February 21, 1996
----------

Contents of Network Services Lecture

  1. Overview of network services
    1. Starting Services under Unix
    2. Service names vs. port numbers
    3. Other services
  2. Automatic service starting: inetd
    1. inetd configuration file
  3. Setting up your own service
    1. doserver
    2. What's going on here?
    3. Interactive service
    4. SumServer example

Overview of network services


Starting Services under Unix



What is a service?

Examples of some standard internet services:


Trying out services under unix: telnet

rohan% telnet moria daytime
Trying 130.191.1.10...
Connected to moria.sdsu.edu.
Escape character is '^]'.
Wed Feb 21 20:41:44 1996
Connection closed by foreign host.
rohan%


Service names vs. port numbers


IP only knows about port numbers. What gives?


/etc/services provides a mapping from service name to port number and protocol type.

example lines from /etc/services:

echo7/tcp
echo7/udp
discard9/tcpsink null
discard9/udpsink null
systat11/tcpusers
daytime13/tcp
daytime13/udp
netstat15/tcp
chargen19/tcpttytst source
chargen19/udpttytst source
ftp-data20/tcp
ftp21/tcp
telnet23/tcp
smtp25/tcp

Other services


Some services aren't mentioned in /etc/services


example: POP (Post Office Protocol) used by Eudora

rohan% telnet rohan 110
Trying 130.191.143.100...
Connected to rohan.sdsu.edu.
Escape character is '^]'.
+OK QUALCOMM Pop server derived from \
UCB (version 2.1.4-R3) at rohan starting
HELP
-ERR Unknown command: "help".
QUIT
+OK Pop server at rohan signing off.
Connection closed by foreign host.
rohan%

Other examples:



Automatic service starting: inetd



Services are provided by a program.


A program which provides a service and always runs is called a daemon


Problems with daemons:

Each daemon is a process

Many services are used infrequently

Result: Lots of wasted resources.


Unix solution: The Internet Super Daemon inetd

inetd starts services only when they are requested.

uses a configuration file to determine what services to make available: /etc/inetd.conf

services do not have to be started at system startup time.


inetd configuration file



Format

Each line contains the following fields separated by TABs:

<service_name> <socket_type> <proto> <flags> <user> <server_pathname> <args>


Example entry for the ftp service:

telnet stream tcp nowait root /usr/sbin/in.telnetd in.telnetd


Notes from the SysAdmin:

inetd and inetd.conf are ugly and hard to maintain.

BUT: it works.


Setting up your own service


Can't use inetd. Why?

The <service_name> field in /etc/inetd.conf needs to be a service mentioned in /etc/services

/etc/services can only be modifed by the system administrator.


Simple workaround: We have a SDSU-grown inetd

Mark Boyns <boyns@sdsu.edu> wrote a 49 line perl program which can help us.

~turtle/doserver


Usage:

~turtle/doserver "<program>"


doserver


For example: (requires two windows...)

rohan% ~turtle/doserver "/bin/echo `Hello there'"
Using port 2748


moria% telnet rohan 2748
Trying 130.191.143.100...
Connected to rohan.sdsu.edu.
Escape character is '^]'.
Hello there
Connection closed by foreign host.
moria%

When this happens, the rohan window will have the following:

rohan% ~turtle/doserver "/bin/echo 'Hello there'"
Using port 2748
130.191.1.10 connected
client connection closed

Quit the sevice on rohan with Control-C


What's going on here?


We have implemented an internet service without writing any code. Huh?


Under Unix, all I/O will at some level appear as file I/O.

doserver (and inetd) assigns the standard in and standard out of the program to the network connection.


What does this mean?

If a service is to be started by something like inetd or doserver, the program that implements the service only has to worry about STDIN and STDOUT.


Interactive service


import sdsu.SDSU;

public class SumServer
{

public static void main(String arg[]) throws Exception
{
System.out.print("Enter a number: ");
System.out.flush();
int one = SDSU.in.readInt();

System.out.print("Enter another number: ");
System.out.flush();
int two = SDSU.in.readInt();

System.out.println("The sum is " + (one + two));
}

}


Start server on moria:

moria% ~turtle/doserver "java SumServer"
Using port 2748


SumServer example


Use telnet on rohan to communicate with your service:

rohan% telnet moria 2748
Trying 130.191.1.10...
Connected to moria.sdsu.edu.
Escape character is `^]'.
Enter a number: 15
Enter another number: 8
The sum is 23
Connection closed by foreign host.
rohan%



Note that this service can be reached from anywhere on the internet.

The only problem now is to let other people know about your neat-o service.

----------