The internet relies on various protocols to ensure smooth communication between devices. These protocols are like languages that computers use to talk to each other, each serving a specific purpose. Let's focus mostly on HTTP first, as it is the most relevant to web programming. We will explore other relevant protocols afterwards:
Port: 80
Purpose: The foundation of data communication on the web.
How it works:
Client (your browser) sends a request to a server.
Server responds with the requested data (usually web pages).
Data is sent in plain text, making it vulnerable to interception.
Port: 443
Purpose: Secure version of HTTP.
How it works:
Uses SSL/TLS protocols to encrypt data.
Provides authentication of the accessed website.
Protects the privacy and integrity of exchanged data.
Client: Typically a web browser that sends requests to the server. E.g. Google Chrome
Server: A computer that hosts the website or web application and responds to client requests. E.g. Flask server.
Client sends a request: When you type a URL or click a link, your browser sends an HTTP request.
Server processes the request: The server (e.g., your Flask application) receives and processes the request.
Server sends a response: The server sends back an HTTP response, usually containing the requested content.
Client processes the response: Your browser renders the received content (HTML, CSS, JavaScript).
HTTP defines several request methods that indicate the desired action to be performed on the identified resource.Â
GET: Retrieve data from the server (e.g., loading a webpage)
POST: Submit data to be processed by the server (e.g., submitting a form)
PUT: Update an existing resource on the server
DELETE: Request the server to delete a specified resource
We have used two of these in our Flask applications: GET and POST. E.g.
@app.route('/resource', methods=['GET', 'POST'])
def handle_resource():
    if request.method == 'POST':
        # Handle POST request
    else:
        # Handle GET request
HTTP responses include status codes that indicate the outcome of the request. Here are some common ones:
200 OK: Standard response for successful HTTP requests
201 Created: Request has been fulfilled, resulting in the creation of a new resource
301 Moved Permanently: This and all future requests should be directed to the given URI
404 Not Found: The requested resource could not be found
403 Forbidden: The server understood the request but refuses to authorize it
500 Internal Server Error: A generic error message when an unexpected condition was encountered
HTTP headers allow the client and server to pass additional information with the request or response. Common headers include:
Content-Type: Indicates the media type of the resource (e.g., text/html, application/json)
User-Agent: Contains information about the client software
Cookie: Contains stored HTTP cookies
Authorization: Contains credentials for authenticating the client with the server
Query Parameters: Additional data sent in the URL (e.g., ?key1=value1&key2=value2)
Request Body: Data sent in the body of POST or PUT requests
Ports: Various (depending on the application)
Purpose: The fundamental suite of protocols that the internet is built upon.
How it works:
TCP ensures reliable, ordered delivery of data.
IP handles addressing and routing of data packets.
Key features:
Connection-oriented (establishes a connection before sending data)
Error-checking and recovery mechanisms
Port: 53
Purpose: Translates human-readable domain names into IP addresses.
How it works:
You type "www.example.com" in your browser.
DNS server translates this to an IP address (e.g., 93.184.216.34).
Your browser connects to this IP address.
Port: 21 (control), 20 (data transfer)
Purpose: Transferring files between computers over a network.
Limitation: Data and passwords are sent in plain text.
Port: 22
Purpose: Secure version of FTP.
How it works:
Uses SSH (Secure Shell) to encrypt data and commands.
Provides stronger authentication and data integrity.
Port: 443 (when used with HTTPS)
Purpose:
Original protocol for establishing encrypted links between web servers and browsers.
Ensures data privacy, integrity, and authentication.
Status:
Deprecated due to security vulnerabilities. Succeeded by TLS.
Port: 443 (when used with HTTPS)
Purpose:
Successor to SSL, providing improved security and performance.
Ensures confidentiality and data integrity between communicating applications.
Key Features:
Stronger encryption algorithms
More secure handshake process
Backward compatibility with SSL
Port: 25 (unencrypted), 587 (encrypted)
Purpose: Sending email between servers.
Port: 110 (unencrypted), 995 (encrypted)
Purpose: Retrieving email from a server to a single computer. Usually downloads and deletes emails from the server.
Port: 143 (unencrypted), 993 (encrypted)
Purpose: Retrieving email from a server to multiple devices. Keeps emails on the server, allowing access from multiple devices.