Course contentsShow
← Computer Science
Lesson 1541 of 2,87235. Application Layer ProtocolsFree lesson

Socket Fundamentals and Client-Server Model

Learn what sockets are, how they enable network communication, and the basic client-server architecture.

Socket Fundamentals and Client-Server Model

What you'll learn: How sockets work as the programming interface that lets applications communicate over networks.

What Is a Socket?

A socket is a software endpoint that allows two programs (often on different machines) to communicate over a network. Think of it as a "phone jack" for your application—just as you plug a phone into a jack to make calls, your program creates a socket to send and receive data over the network.

Sockets abstract away all the complexity you've learned: IP addresses, TCP/UDP protocols, port numbers, handshakes, and packet delivery. Instead of manually crafting TCP segments or UDP datagrams, you simply open a socket, connect it, and read/write data.

The Client-Server Architecture

Most networked applications follow the client-server model:

  • Server: A program that listens on a specific port, waiting for incoming connection requests. It creates a socket, binds it to an IP address and port number, then waits (listens) for clients.

  • Client: A program that initiates communication by creating a socket and requesting a connection to the server's IP address and port.

The Flow

  1. Server creates a socket and binds it to port 80 (for HTTP, for example)
  2. Server listens for incoming connections
  3. Client creates a socket and connects to the server's IP:port
  4. Once connected (for TCP), both can send/receive data through their sockets
  5. Either side closes the socket when done

The socket handles all the TCP handshake, sequence numbers, acknowledgments, and retransmissions you've already studied—your application just sees a stream of bytes.

Key Takeaway: Sockets are the programming interface between applications and transport protocols (TCP/UDP), enabling the client-server model where servers listen for connections and clients initiate them.