[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Communications Programming Concepts

Sockets Overview

In the operating system, sockets have the following characteristics:

Critical Attributes

Sockets share certain critical attributes that no other IPC mechanisms feature:

Application programs request the operating system to create a socket when one is needed. The operating system returns an integer that the application program uses to reference the newly created socket. Unlike file descriptors, the operating system can create sockets without binding them to a specific destination address. The application program can choose to supply a destination address each time it uses the socket.

Sockets Background

Sockets were developed in response to the need for sophisticated interprocess facilities to meet the following goals:

Sockets provide a sufficiently general interface to allow network-based applications to be constructed independently of the underlying communication facilities. They also support the construction of distributed programs built on top of communication primitives.

Note: The socket subroutines serve as the application program interface for Transmission Control Protocol/Internet Protocol (TCP/IP) and XNS (Xerox Network Systems).

Socket Facilities

Socket subroutines and network library subroutines provide the building blocks for IPC. An application program must perform the following basic functions to conduct IPC through the socket layer:

Creating and Naming Sockets

A socket is created with the socket subroutine. This subroutine creates a socket of a specified domain, type, and protocol. Sockets have different qualities depending on these specifications. A communication domain indicates the protocol families to be used with the created socket. The socket type defines its communication properties such as reliability, ordering, and prevention of duplication of messages. Some protocol families have multiple protocols that support one type of service. To supply a protocol in the creation of a socket, the programmer must understand the protocol family well enough to know the type of service each protocol supplies.

An application can bind a name to a socket. The socket names used by most applications are readable strings. However, the name for a socket that is used within a communication domain is usually a low-level address. The form and meaning of socket addresses are dependent on the communication domain in which the socket is created. The socket name is specified by a sockaddr structure.

Accepting and Making Socket Connections

Sockets can be connected or unconnected. Unconnected sockets are produced by the socket subroutine. An unconnected socket can yield a connected socket pair by:

Other types of sockets, such as datagram sockets, need not establish connections before use.

Transferring Data

Sockets include a variety of calls for sending and receiving data. The usual read and write subroutines can be used on sockets that are in a connected state. Additional socket subroutines permit callers to specify or receive the address of the peer socket. These calls are useful for connectionless sockets, in which the peer sockets can vary on each message transmitted or received. The sendmsg and recvmsg subroutines support the full interface to the IPC facilities. Besides offering scatter-gather operations, these calls allow an address to be specified or received and support flag options.

Shutting Down Socket Operations

Once sockets are no longer of use they can be closed or shut down using the shutdown or close subroutine.

Translating Network Addresses

Application programs need to locate and construct network addresses when conducting the interprocess communication. The socket facilities include subroutines to:


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]