- application program interface
- how an application program gets access to os, or any, services
- there are many apis - differ in form and use; sockets; tli-xli; plan 9
- good programmers immediately hide the api - wrappers, libraries;
efficiency
- the sockets api
- developed at berkeley in the early 80s; 4.1 bsd
- the evils of too much generality - protocols, addresses
- re-implemented (ported) many times - winsock on windows
- many other sockets-like and sockets-based apis - shells, scripting
languages, libraries
- general characteristics
- there is a difference between
- connection-oriented and connection-less communication - different
set-up, use, and tear-down
- clients and servers - different system calls, asymmetric behaviors
(not like pipes)
- socket manipulation is detailed - many steps, with different detail at
each step
- many api routines (18 socket specific), almost all used.
- basic approach - set-up, communicate, shut-down (tcp oriented)
- clients
- create a socket (the active socket)
- connect to the server
- communicate
- shut-down, or close, or tear-down
- servers
- create a socket (the listener or the passive socket)
- give the socket an endpoint address (binding)
- wait for client requests
- create a new socket for each request (the active socket)
- communicate over the new connection
- shutdown the new connection
- endpoints and connections
- an endpoint is a three-tuple (ip addr, port no, protocol).
- undefined - no ip addr or port no
- unresolved - wildcard ip addrs or port nos, servers
- resolved - a specific ip addr and port no
- a connection is a pair of fully resolved endpoint addresses - a
five-tuple, because protocols must match; udp included; local and
remote (or foreign) endpoints
- the two questions to understand the sockets interfaces
- when does an endpoint become resolved (what is the state of an
endpoint at any time)
- when do endpoints get paired into a connection (and how)
- the set-up api
-
socket()
- create a socket with the undefined endpoint (?, ?, p)
-
bind()
- assign an ip addr and port no to a socket; the local part
of a connection pair; may be unresolved; client and server optional
-
connect()
- resolve both endpoints in a connection; clients only
-
listen()
- resolve the local endpoint; make it a listener;
establish the connection queue; server only
-
accept()
- retrieve the next connection from the connection queue;
returns a new socket with a new connection and a new, resolved local
endpoint; server only; blocks on empty queues
- the shut-down api
- closing is not the same as shutting down - full duplex connection; data
draining from the network; shared data among processes
-
close()
- reference counted, full duplex, recovers resources
-
shutdown()
- per process, half duplex, does not recover resources
- the communication api
- where to send on connection-less communication - sender identifies
receiver
-
read()
and write()
- the usual
-
recvfrom()
and sendto()
- remote endpoint information
This page last modified on 7 February 2002.