Main Page | See live article | Alphabetical index

Berkeley sockets

The Berkeley sockets application programming interface (API) comprises a library for developing applications written in the C programming language that access a computer network.

Berkeley sockets (also known as the BSD socket API) originated with the 4.2BSD system (released in 1983) as an API, covered under the BSD license, for development of sockets. Only in 1989, however, could UC Berkeley release versions of its operating system and networking library free from the licensing constraints of the Open Group's copyright-protected UNIX operating system.

The Berkeley socket API forms the de facto standard abstraction for network sockets. Most other programing languages use a similar interface as the C API.

Table of contents
1 The Header Files
2 The client side
3 The server side
4 Blocking vs. NonBlocking

The Header Files

The Berkeley socket development library has many associated header files. They include:

 Definitions for the most basic of socket structures with the BSD socket API
 Basic data types associated with structures within the BSD socket API
 Definitions for the socketaddr_in{} and other base data structures.
 Definitions and data type declarations for SOCK_UNIX streams

The client side


gethostbyname() and gethostbyaddr()


The server side





Programmers use accept() to satisfy a connection request from a remote host. A specified socket on the local host (which must have the capability of accepting the connection) connects to the requesting socket on the remote host. The code returns the remote socket's socket address.

Blocking vs. NonBlocking

Berkeley sockets can operate in one of two modes: blocking or non-blocking. A blocking socket will not "return" until it has sent (or received) all the data specified for the operation. This may cause problems if a socket continues to listen: a program may hang as the socket waits for data that may never arrive.

See also:

This article was originally based on material from FOLDOC, used with permission. Update as needed.