Network - (Internet) (Socket|Endpoint)

1 - About

A network socket is a network connection between a server (local machine) and a client (remote machine).

This connection is implemented by a software (not hardware) by creating a network interface.

A socket is therefore an endpoint of an inter-process communication flow across a computer network.

Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets.

A TCP/IP socket is a socket that use TCP has protocol. See internet

3 - Definition

3.1 - Internet

An Internet socket is characterized by a unique combination of the following:

  • Local socket address: Local IP address and port number
  • Remote socket address: Only for established TCP sockets. This is necessary since a TCP server may serve several clients concurrently. The server creates one socket for each client, and these sockets share the same local socket address
  • Protocol: A transport protocol (e.g., TCP, UDP, raw IP, or others). TCP port 53 and UDP port 53 are consequently different, distinct sockets.

3.2 - Reference

The term socket can refer to / is specified as:

  • an entity that is uniquely identified by the socket number (IETF Request for Comments, Internet Standards)
  • a local socket address, i.e. a combination of an IP address and a port number.
  • a 32 bit number with even sockets identifying receiving sockets and odd sockets identifying sending sockets. ( original definition of socket given in RFC 147, as it was related to the ARPA network in 1971)

3.3 - Type

Not to be coufound with the message protocol There are several Internet socket types available:

  • Datagram sockets, also known as connectionless sockets, which use User Datagram Protocol (UDP)
  • Stream sockets, also known as connection-oriented sockets, which use Transmission Control Protocol (TCP) or Stream Control Transmission Protocol (SCTP).
  • Raw sockets (or Raw IP sockets), typically available in routers and other network equipment. Here the transport layer is bypassed, and the packet headers are made accessible to the application.

There are also non-Internet sockets, implemented over other transport protocols, such as:

  • Systems Network Architecture (SNA).
  • Unix domain sockets (UDS), for internal inter-process communication.

3.4 - Identifier

Within the operating system and the application that created a socket, a socket is referred to by a unique integer number called socket identifier or socket number.

4 - Socket Lifecyle

4.1 - Initialization

Computer processes that provide application services are called as servers, and create sockets on start up that are in listening state. These sockets are waiting for initiatives from client programs.

Socket communications are nowadays bidirectional.

4.2 - Implementation by Protocol

4.2.1 - TCP

A TCP server may serve several clients concurrently, by creating a child process for each client and establishing a TCP connection between the child process and the client.

Unique dedicated sockets are created for each connection. These are in established state, when a socket-to-socket virtual connection or virtual circuit (VC), also known as a TCP session, is established with the remote socket (providing a duplex byte stream)

A server may create several concurrently established TCP sockets with the same local port number and local IP address, each mapped to its own server-child process, serving its own client process.

They are treated as different sockets by the operating system, since the remote socket address (the client IP address and/or port number) are different; i.e. since they have different socket pair tuples.

For further details on TCP sockets, including other states of TCP sockets, see Transmission Control Protocol.

4.2.2 - UDP

A UDP socket cannot be in an established state, since UDP is connectionless. Therefore, netstat does not show the state of a UDP socket. A UDP server does not create new child processes for every concurrently served client, but the same process handles incoming data packets from all remote clients sequentially through the same socket. This implies that UDP sockets are not identified by the remote address, but only by the local address, although each message has an associated remote address.

4.3 - Incoming packets processing

The operating system forwards the payload of incoming IP packets to the corresponding application by extracting the socket address information from the IP and transport protocol headers and stripping the headers from the application data.

5 - Management

5.1 - List

On Unix-like and Microsoft Windows based operating systems the netstat command line tool may be used to list all currently established sockets.

5.2 - Count

  • Number of open sockets with netstat
netstat | grep port


6 - Language

  • Java: For IPC, you could also use ObjectOutputStream and ObjectInputStream connected to network sockets and exchange Java objects directly between the two programs. Or you could design your own protocol.

7 - Documentation / Reference

network/socket.txt · Last modified: 2018/10/05 10:24 by gerardnico