- How an application program gets access to os, or any, services
- IP doesn't specify or even recommend an API for services.
- It illustrates an example API.
- There are many TCP/IP APIs, differing in form and use
- BSD sockets is the most common.
- AT&T SYS V TLI interface.
- Plan 9 file-system based interface.
- Good programmers immediately hide the API.
- Simplifies complex interfaces.
- Increases portability.
- 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.
- Socket manipulations are detailed.
- There are many steps, with different detail at each step.
- There are many socket routines (18 socket specific).
- Almost all are used, some counter-intuitively.
- Connecting a UDP endpoint.
- An endpoint represents the ability to communicate using TCP or
UDP.
- () An endpoint is an (IP addr, port no, protocol) three-tuple.
- The IP address through which data flows (multi-homed hosts).
- The port number involved in the data flow.
- Port numbers are held by processes (or threads).
- The protocol involved in moving the data.
- Remember
www.monmouth.edu:80
is ambigouous.
- A socket is an implementation of an endpoint.
- An endpoint component is either defined or undefined.
- The protocol component is defined when the socket is created.
- A defined component is either resolved or unresolved.
- A resolved component has a definite value.
- An unresolved component is a wildcard.
- Understand the current endpoint state and how i is changed.
- A socket is created with an undefined IP address and port number.
- A pair of endpoints forms a connection.
- IP transmissions always require two endpoints.
- Except for multi- or broadcasts.
- An IP connection is the five-tuple formed from the two endpoints.
( | IP addrlocal, | port numberlocal, |
| protocol, | |
| IP addrremote, | port numberremote) |
- TCP connections are explicit and permanent.
- UDP connections are implicit and ephemeral.
- Understand when and from which endpoints connections get made.
- There are four basic patterns of socket API use.
- Remember clients and servers aren't fixed.
- A client may respond and a server may initiaite.
- Create a socket.
- Establish the remote endpoint.
- Send data.
- Close the socket.
- Create a socket.
- Establish the local endpoint.
- Receive data.
- Close the socket.
- 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
-
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
- 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
- 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 30 January 2003.