Information Technology Reference
In-Depth Information
• Network interfaces support multiple protocols, each with differing addressing
requirements so that, for example, a 32-bit identifier is not sucient for
holding network addresses for all protocols.
Network interfaces therefore
need to be generalised.
Sockets provide a low-level interface to network protocols. For anything other
than simple message exchanges, protocols are developed to exchange messages in
specific formats. Due to the stream-oriented nature of the UNIX I/O system,
this is a particularly onerous task as the programmer is required to implement
packet assembly and disassembly, which differs depending on the protocol being
implemented. In addition, error handling and recovery is left entirely up to the
programmer, making socket development dicult and error prone.
This section provides an overview and evaluation of the BSD socket interface
and illustrates its usage through a simple application.
2.2.1
BSD Socket Interface
As previously mentioned, there are a number of similarities between file and net-
work I/O operations. The BSD socket interface attempts to provide as much sim-
ilarity as possible while allowing additional network-based operations. Table 2.1
provides an overview of the differences and similarities between the socket and file
operations.
Figure 2.1 provides an overview of the steps required for both client and
server to initiate a transfer for a connection-oriented transfer. This interaction
can be summarised as:
Server interaction. Firstly, the server obtains a socket via the socket() call and
then bind() is called, which assigns a name to the socket. Next listen() is
called to indicate that the application is willing to accept connection requests.
As well as the socket, the listen() call also accepts a backlog parameter,
which stipulates the number of connection requests that can be queued by the
system while it waits for the accept() call to be executed. If a connection
attempt arrives and the queue is full, the connection is refused. Finally
accept() is called, which suspends the application until a connection request
arrives from the client.
Client interaction. A socket is obtained via the socket() call and then connect()
is called with a parameter stipulating the socket and the address of the
server. The address is passed in the sockaddr structure and contains the
local address, the remote address, and the protocol to use. Once a connection
has been established, messages can be exchanged between the two systems.
For both of the above, the close() call can be used to close the connection
and the shutdown() call can be used to close part of the connection, either
reads or writes.
The socket API also provides the select() function, which is used to provide
I/O multiplexing by allowing the programmer to examine a set of file descriptors
Search WWH ::




Custom Search