What is a Protocol?

Estimated read time: 1:20

    Learn to use AI like a Pro

    Get the latest AI workflows to boost your productivity and business performance, delivered weekly by expert consultants. Enjoy step-by-step guides, weekly Q&A sessions, and full access to our AI workflow archive.

    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo
    Canva Logo
    Claude AI Logo
    Google Gemini Logo
    HeyGen Logo
    Hugging Face Logo
    Microsoft Logo
    OpenAI Logo
    Zapier Logo

    Summary

    This video from IIT Madras's B.S. Degree Programme explores the concept of protocols, focusing on HTTP in web communication. Protocols are vital as they define the rules and conventions for interaction between entities, similar to social norms. The video explains the importance of protocols in computer communication, detailing how HTTP allows for text-based exchanges, interprets requests, and provides responses through status codes and headers. It also demonstrates setting up a basic Python HTTP server, illustrating practical examples of GET and POST requests, and how HTTP headers and status codes play a critical role in determining the nature of web interactions.

      Highlights

      • Protocols ensure that computers know how to communicate, much like how humans greet each other. 😊
      • HTTP uses plain text for requests and responses, allowing for easy readability and debugging. 🕵️
      • Various status codes are part of HTTP, indicating success, errors, or redirects (like 200, 404, 500). 📟
      • GET requests are simple and often used in searches, while POST sends large data blocks, like emails. ✉️
      • Demonstrating a Python HTTP server shows practical examples of how protocols operate. 🐍

      Key Takeaways

      • Protocols are like social rules for computers, ensuring smooth communication. 💬
      • HTTP is a text-based protocol, making it easy to understand requests and responses. 📜
      • Status codes are crucial in HTTP for understanding responses (like 404 for 'not found'). 🚫
      • GET and POST are common HTTP requests, with GET used for simple data retrieval and POST for complex submissions. 📧
      • Setting up a simple Python web server can help illustrate how HTTP protocols function. 🖥️

      Overview

      In the realm of computer communication, protocols are akin to the social niceties we have as humans. Just as you wouldn't start a conversation by shouting randomly, computers rely on protocols to ensure they exchange information correctly. This video delves into HTTP, a fundamental protocol that dictates how data moves across the web.

        HTTP is notable for its text-based nature, making interactions clear and readable, which assists in debugging and understanding transactions between clients and servers. The use of status codes, such as 200 and 404, provide quick references to the state of a request, like success or missing pages. Understanding these codes is key to navigating and developing for the web.

          A practical demonstration using Python's simple HTTP server shows the nuts and bolts of the HTTP protocol in action. It illustrates how requests work, how servers respond, and the significance of headers and mime types in conveying information effectively. Through this server, the video offers a hands-on way to grasp how web communications happen effortlessly yet intricately.

            Chapters

            • 00:00 - 01:00: Introduction and Concept of Protocol The chapter introduces the course on modern application development.
            • 01:00 - 02:00: Protocols in Computer Communication The chapter 'Protocols in Computer Communication' explains the concept of protocols as a mutual agreement on communication methods between two parties. This is likened to human social interactions where individuals follow certain protocols like smiling, greeting, and exchanging names. Similarly, computers have protocols they must adhere to for effective communication.
            • 02:00 - 03:00: Hypertext Transfer Protocol (HTTP) In this chapter, we explore the fundamentals of the Hypertext Transfer Protocol (HTTP). The key point of discussion is the necessity for a communication protocol that defines the type of requests a client can make and what kind of responses are expected. Without such a protocol, there would be a lack of understanding between a client and server during communication, especially if random text or unrecognized commands are sent. HTTP serves to standardize this communication process, ensuring that both the client and server are aligned in their exchange of information.
            • 03:00 - 04:00: HTTP Methods and Status Codes The chapter discusses how a client and server communicate through requests and responses as per the Hypertext Transfer Protocol (HTTP). It explains that the server can provide different responses based on the information about the client. The protocol dictates how these communications occur, highlighting the specifics of HTTP in managing these interactions.
            • 04:00 - 05:00: Setting Up a Simple Python Web Server This chapter discusses the nature of data exchanged between client and server, focusing on the readability of HTTP header information. The text-based nature of this information allows for human interpretation, as one can see explicit HTTP methods like 'GET' in the transmitted data. This transparency means that if someone monitors the data packets being exchanged, they can identify the type of requests, such as GET requests, being made to the server.
            • 05:00 - 06:00: Automatic Directory Listings and Convention This chapter discusses the use of headers in HTTP requests and responses. It explains how headers contain information about the types of languages, encodings, and responses a client can accept, as well as metadata about the message itself. The chapter also highlights the importance of status codes such as '200 OK' and '404 Not Found', which give an indication of the result of an HTTP request. The role of headers in caching and reusing information is also touched upon.
            • 06:00 - 07:00: HTTP Headers and Response Details This chapter delves into HTTP headers and response codes, focusing on the most common ones used in web communications. The chapter highlights the significance of HTTP status codes, explaining the implications of codes like 200 (OK), 404 (Not Found), and 500 (Internal Server Error), with emphasis on the undesirability of server errors like the 500 code. It also touches on 300 series codes, describing them as more of warnings than actual errors, thus providing a concise understanding of HTTP responses in web technology.
            • 07:00 - 08:00: Content Types and File Serving This chapter discusses different types of HTTP methods and their use cases in web servers, focusing primarily on the GET and POST methods. GET is typically employed for simple requests and retrieving information, such as when conducting search queries with search engines like Google. In contrast, POST is designated for more complex operations.
            • 08:00 - 09:00: Server Response Examples The chapter discusses the differences between GET and POST methods in web forms. It highlights that while GET is suitable for simple data, POST is more appropriate for sending large blocks of text or complex data, such as when sending an email via Gmail.
            • 09:00 - 10:00: MIME Types and Server Configuration The chapter discusses various HTTP request methods beyond the commonly known GET and POST, highlighting the less common but important methods like PUT and DELETE. These methods are especially relevant in the context of web 2.0 and dynamic websites. The chapter also introduces APIs (Application Programming Interfaces), specifically focusing on popular ones like REST and CRUD interfaces, which will be explored further in relation to databases.
            • 10:00 - 11:00: Conclusion and Additional Examples In conclusion, the chapter highlights additional examples related to the previously discussed protocol concepts. The author demonstrates a more complex web server setup using a simple command-line instruction. The focus is on executing a task using the Python interpreter, where the '-m' flag signifies executing a specific module or component. The example serves to illustrate the practical application of the protocol parts in a real-world scenario, reinforcing the chapter's educational objectives.

            What is a Protocol? Transcription

            • 00:00 - 00:30 [Music] hello everyone and welcome to this course on modern application development okay so now let's sort of try and understand we have seen an example of what a web communication looks like let us try and understand a little bit more about what is a protocol and some examples in the context of http
            • 00:30 - 01:00 right so like i said a protocol basically means that both sides of some communication agree on how to talk to each other right so for example when we walk into a room the usual protocol that we are expected to follow is that we smile at whoever we see we greet them exchange names may be right possibly shake hands those are all part of a protocol that we follow okay that's between human beings in the same way right you also have protocols for how computers are expected to communicate with each other
            • 01:00 - 01:30 right now if i connect to another computer on port 1500 i need to know what kind of information it is expecting and what it is likely to respond with ok so if i go there and just start typing text the other side is most likely not going to understand what i am talking about okay which is why we need to sort of have a protocol which specifies the nature of my request what kind of responses i am expecting to see what i am as a client right
            • 01:30 - 02:00 and what kind of responses i can actually deal with right so the server now has more information about me and can respond accordingly so the client is also you know asking the server for something the server is then responding based on what the client accepted these two things how do they communicate with each other is what constitutes the protocol now the hypertext transfer protocol is a very specific version of a type of protocol right
            • 02:00 - 02:30 it is primarily text based what i mean by that is as you saw already most of the actual information the header information is encoded as text so you can actually read the information right so you can see a get and you can actually see it its not that you know its been interpreted as get or something like its not a number which got interpreted as get it actually has get in the text which means that if you happen to see the back and forth you know you look at the bytes on the wire as they are passing by you can see that this is actually a get request going to the server
            • 02:30 - 03:00 it also you know the headers can be used to convey a lot of extra information what kind of languages you are willing to accept what kind of encodings what kind of response types you expect to see and so on similarly the response headers will also be in text and convey information about the message itself right also about whether this information can be cached and used later and most importantly status codes we already saw the 200 ok and like i said you know the 404 not found there are
            • 03:00 - 03:30 many other codes that are defined as part of the http specification these are obviously the most common ones right 200 ok is what you hope to see most of the time 404 happens once in a while 500 is something you really do not want to see because it means server error right something crashed the server crashed or something happened over there right there are similar ones i mean there are a bunch of like 300 errors which are sort of harmless they sort of are just warnings more than errors
            • 03:30 - 04:00 and various different kinds of codes that are defined as part of the http specification so what are these use cases right as we saw already with the simple web server get is used for the most simple requests it just requests information gets back data so most of the time things like search queries and so on when you are like you know connecting to google and doing a search most of the time what you would probably be doing would be a get right post can be used for more complex
            • 04:00 - 04:30 data let us say you have a form with multiple fields in it right there is a name and address various other things you cannot encode all of that into a get at least you can do it easily right post is a much better way of doing this it can accept large blocks of text so for example even in gmail when you are typing in an email and hitting send that entire block of information is finally being posted to the web server which accepts it puts it together constructs an email out of it and sends
            • 04:30 - 05:00 it right there are many other requests as well right some of them called put something called delete there are you know a few other variants which are much less common but are used quite extensively especially in web 2.0 in the dynamic web right and many sort of apis application programming interfaces including the so called rest interface and crud interfaces to databases that we will look at later
            • 05:00 - 05:30 are sort of built around these kind of these parts of the protocol so just to you know give a few more examples what i am going to do now is run something a slightly more complex web server right so this is again a one liner i am just running the python interpreter right and the dash m basically says to execute something right and what is that something it
            • 05:30 - 06:00 basically says take the module http and run the function server from inside the http module okay so in some sense this is a one line web server right if i go back to my shell script i can basically kill this and clear this as well and if i now write run this command python minus m http dot server it now gives me a little bit more
            • 06:00 - 06:30 information than my shell script right it actually tells me serving http on zero zero zero zero so this is the local ip address well more importantly this actually says on any ip address that this machine is connected to it also tells me that it is running on port 8000 i didn't specify port 8000 that just happens to be the default used by the python http server module right and so now what happens if i once again run curl minus v http colon slash slash
            • 06:30 - 07:00 localhost colon 8000 i can see that it actually gives me a lot more information out here okay and this is actually surprising when you know its giving me information which is much more than what i expected because i do not really have anything over there right but if you look closely at it you will realize that what it has done is it has automatically created a directory listing
            • 07:00 - 07:30 ok it is showing me the list of files that i have okay so rather than worrying about this what i am going to do is take another couple of examples of what of requests that would go out when i run this python web server and if i use curl in order to connect to it right if i do something like get slash and let say i did not have this particular thing right i did not have a directory listing normally what it would do is
            • 07:30 - 08:00 take a file called text called index.html lets in fact create a file like that right so you can see that index.html i created it such that it just has one line saying hello right even though i call it a dot html file it does not have any tags or anything that you would normally expect to see in a
            • 08:00 - 08:30 html file now what would happen if i run the same thing again i would find that this basically responds by giving me back whatever i had in index.html okay this is actually part of something called convention it is not really part of the http protocol right this is more of a convention which says that in a given directory if i find a file called index.html
            • 08:30 - 09:00 and i just get a request for the directory right get slash or get the directory name go pick up whatever is in index.html and send that back to the requester ok so what we can see right i am going back over here lets look at it in a little bit more detail like i said the first three lines essentially you know the anything with the star is just debugging information these five lines correspond to what was
            • 09:00 - 09:30 sent by curl exactly the same as previously the only difference being that now it is connecting to port 8000 because i told it that the server is running on port 8000 this star again basically is just you know extra information right i mean this is debugging information from curl but the response from the python web server is this bunch of lines ok notice one thing it is using http 1.0
            • 09:30 - 10:00 not 1.1 unlike the previous one that we had it makes life even simpler because 1.0 is actually a very simple version of the protocol 1.1 even though i had 1.1 over there actually requires a little bit more information for it to work it also gives back information about itself it says that it is a simple http server with python 3.9.2 that is the version of python running over here it gives the date but this is part of the header it is not something to be displayed right and then comes the mime type
            • 10:00 - 10:30 of the result right it basically gives the content type and it says it is text slash html right the original one line web server that i had did not have any of this information but ideally it should right because this is what allows the browser to display the information correctly the content type and content length are actually important in pieces of information to have in this case this text slash html is
            • 10:30 - 11:00 useful it basically says treat whatever you are getting now as an html file which means basically displayed if it said application pdf then what would happen is it would download and probably you know open a previewer or something to display it right content length is 31 bytes well that's because i had some information out here which was a total of around 31 bytes or so right it also gives a last modified basically telling you know when was the file that its sending to
            • 11:00 - 11:30 you when was it last modified why is this information useful because from the client's point of view it might find that you know if you are trying to reload a page but the server says it was last modified one week ago and the client might decide ok i do not need to do anything i do not need to change what i am drawing on the page because nothing has changed ok so finally we have the actual text coming back from the index.html index.html5 right so this is sort of the transaction
            • 11:30 - 12:00 that goes back and forth when you do a get slash right just curl http colon local hosts colon 8000 now remember that i had this file serve dot sh sitting over there right and if i tried a request to that get slash serve dot sh what do i expect will be the response a similar set of headers from here except that now the content type it now says is application slash xsh that is just a mime type
            • 12:00 - 12:30 corresponding to a shell script okay and what is the actual data that comes back the script itself ok so in other words any file that you had the server if it is written appropriately should be able to find out the mime type the content type send that back to the client and also send the data as required