Recent Articles



































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.

[Top]

The Header Files

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

<sys/socket.h>

Definitions for the most basic of socket structures with the BSD socket API

<sys/types.h>

Basic data types associated with structures within the BSD socket API

<netinet/in.h>

Definitions for the socketaddr_in{} and other base data structures.

<sys/un.h>

Definitions and data type declarations for SOCK_UNIX streams
[Top]

The client side

[Top]

socket()

[Top]

gethostbyname() and gethostbyaddr()

[Top]

connect()


[Top]

The server side

[Top]

socket()

[Top]

bind()

[Top]

listen()

[Top]

accept()

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.

[Top]

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: Computer network

[Top]

External lniks

This article was originally based on material from the Free On-line Dictionary of Computing and is used under the GFDL.





  View Live Article   This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License