Socket Programming for Computer Networks

Definition: Sockets are the fundamental technology for programming software to communicate on TCP/IP networks. A socket provides a bidirectional communication endpoint for sending and receiving data with another socket. Socket connections normally run between two different computers on a LAN or across the Internet, but they can also be used for interprocess communication on a single computer.

Socket Libraries

Network programmers typically use socket libraries rather than coding directly to lower level socket APIs.

The two most commonly use socket libraries are Berkeley Sockets (for Linux/Unix systems) and WinSock (for Windows systems).

A socket library provides a set of API functions similar to those programmers use for working with files, such as open(), read(), write() and close().

Sockets and Addresses

Socket endpoints on TCP/IP networks each have a unique address that is the combination of an IP address and a TCP/IP port number. When creating a new socket, the socket library automatically generates a unique port number on that device, and the programmer can also specify their own port numbers in specific situations.