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%
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:
echo | 7/tcp | |
echo | 7/udp | |
discard | 9/tcp | sink null |
discard | 9/udp | sink null |
systat | 11/tcp | users |
daytime | 13/tcp | |
daytime | 13/udp | |
netstat | 15/tcp | |
chargen | 19/tcp | ttytst source |
chargen | 19/udp | ttytst source |
ftp-data | 20/tcp | |
ftp | 21/tcp | |
telnet | 23/tcp | |
smtp | 25/tcp |
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:
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.
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.
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>"
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
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.
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
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.