1 of 7

Computer Networks

LECTURE # 12

PORTS AND SOCKETS

2 of 7

What are Ports?

  • Definition: Ports are numerical identifiers in the transport layer of the Internet Protocol Suite (TCP/IP) that help differentiate between multiple services or applications running on a server.
  • Purpose:
    • Allow multiple network services (like web servers, email servers) to operate simultaneously on a single device.
    • Enable routing of data packets to specific applications.

3 of 7

2. Types of Ports

  • Well-Known Ports: Range from 0 to 1023. Reserved for widely used protocols.
    • Examples:
      • HTTP (80), HTTPS (443), FTP (21), SSH (22)
  • Registered Ports: Range from 1024 to 49151. Used by software applications that are user-defined or proprietary.
    • Examples: Microsoft SQL Server (1433), MySQL (3306)
  • Dynamic/Private Ports: Range from 49152 to 65535. Used dynamically by client applications when establishing connections.

4 of 7

3. What are Sockets?

  • Definition: Sockets are endpoints for sending and receiving data across a network. They comprise an IP address and a port number.
  • Socket Types:
    • Stream Sockets (TCP): Provide reliable, ordered, byte-stream communication. Used for applications where data integrity is critical (e.g., web browsers).
    • Datagram Sockets (UDP): Provide connectionless communication. Suitable for applications where speed is more critical than reliability (e.g., online gaming).

5 of 7

4. Sockets in Action

  • How Sockets Work:
    • A server socket listens for incoming client connections on a specified port.
    • When a client socket connects, a dedicated connection is established using a unique source port and the server's listening port.
  • Example of Communication:
    • Client initiates a request to a server using a socket connected to the IP address and port of the server.
    • Server receives the request and responds through the established connection.

6 of 7

5. Practical Applications

  • Client-Server Model: Sockets are widely used in client-server architectures for web applications, online games, and chat applications.
  • APIs and Microservices: Facilitate communication between different services through RESTful APIs or gRPC, often using HTTP/HTTPS ports.

6. Security Considerations

  • Firewalls and Port Filtering: Understanding ports helps in configuring firewalls to allow or deny traffic based on service needs.
  • Securing Sockets:
    • Use of TLS/SSL to encrypt data transmitted over sockets to protect against eavesdropping and man-in-the-middle attacks.

 

7 of 7

Thank You