Unix Network Programming Manual
Sockets
The interprocess communication method used for networking under Berkeley
Unix and its derivatives
utilizes an object known as a socket. There is no physical
manifestation of a socket, rather it is a service provided by
the operating system that makes it appear that there is a connection
between two programs. A socket is similar to a pipe, if you have ever used
a pipe to communicate between two processes. For example,
man socket | lpr
xyzprog | more
In fact, pipes are constructed using a socket internally, so
sockets are a very basic structure. The sockets are implemented as
tables that keep track of the endpoints of the communication through
their addresses, buffer messages passing back and forth and supply
necessary support for different types of communication.
From a programming standpoint, sockets are much like files; they must be
opened, then I/O is performed with the socket, and finally they
are closed. The differences are primarily concerned with the use of
sockets to communicate between different programs running on the same or
different machines.
In the example, the socket is opened with a socket call,
connecteded to a socket opened by another process, used to
send and recv data and finally closed when the
communication is complete. Note that these calls have specific return
values that must be tested in order to determine the appropriate actions
for the program.