Builder · Lesson 07

How does an application open a connection?

A socket gives an application a precise endpoint for network communication: an address, a port, and a transport choice working together.

The application endpoint

A port names a destination. A socket gives the application a handle.

A networked application does not send data to a port in isolation. It uses a socket supplied by the operating system. The socket connects the application to a transport protocol and to an endpoint such as 192.0.2.10:443.

A server socket can listen for incoming conversations. A client socket can connect to that service, exchange data, and close when the conversation is finished.

A socket is an endpoint, not the whole network path.IP and routing move packets toward the host; the transport port and socket let the operating system deliver data to the right application.

Build the model

Four ideas that make a socket useful

01

Address

Identifies the host endpoint, such as an IPv4 or IPv6 address.

02

Port

Identifies the service or process that should receive transport data.

03

Transport

Defines the conversation contract, such as TCP's reliable stream or UDP's datagrams.

04

State

Describes whether the socket is listening, connecting, established, or closing.

Mini experiment

Build a socket conversation

Follow the steps from a listening service to a closed conversation. The endpoint details change as the socket gains state.

SERVERListening0.0.0.0:443
waiting for a client
CLIENTNot connected-

The server has bound to port 443 and is waiting for a client connection.

Knowledge check

Test your socket model

Answer seven questions. The answer order changes each time.

0 / 7