So when you design applications for IoT, you're writing programs, and often these programs interact over a network. So there's a question of how you program to the network. It turns out there's a bunch of APIs that make this process simpler, and so what we're going to do next is we're going to talk about network application programming, to teach you about these APIs and how you can communicate through the network to different devices. It would step back. What we can do is we can go through an example of what happens inside of a web browser. Because this is an application we're probably all familiar with and walk through the steps of what happens, and by understanding these steps, they can help teach you what steps you need to do when you write your own network application. So when you have a web browser. A web browser is a program. Is a program that shows pictures and links, and things like that, let's you click. But behind the scenes, what it's doing is it's translating your clicks into some protocol messages that communicate out through a set of APIs over a network. So browser doesn't have all this code internal to itself. What it does is it works together with your operating system to construct data packets. So the browser has some network code in it and your operating system has some network code inside of its kernel as well, and these two things work together. In particular, the browser communicates with operating system through an API, a set of system calls, or sockets. Now, if you write a browser, you're going to use a set of sockets. There standard sockets called BSD sockets. If you're writing an application for Bluetooth, you're going to write using Bluetooth sockets, and there is ZigBee sockets and Laura sockets. All the different flavors of sockets, but they all have very similar interfaces. So we're going to talk about sockets programming, and by understanding some of the examples I'm going to go through, you're going to know what to do when you write for Bluetooth and all these other different application programming models. So by understanding all these different kinds of sockets, understand the underlying system calls, you'll know how to write your own applications. So to really understand this, let's go through some examples first. So suppose you have your web browser that's running on a computer, your laptop, and there's a server off on the Internet that's storing that web page. So what your laptop needs to do is it needs to communicate with that server and tell it which web page it wants, and then the server needs to send that data back to your laptop. Your laptop needs to be ready and sit there and listen for that. So in particular, there's three steps that need to happen here. First, your laptop needs to tell the server what data it wants. Second, your laptop needs to tell the Internet how to get to that server, and then the third thing it needs to do is it needs to tell the local area network what the next layer to hop is. So how could we do these things? Well, if you think about the network in between your laptop in your server, it's really just a bunch of layer two domains. That's what the Internet is. It's a bunch of different ISPs but in different enterprise networks. Each of these is a single broadcast domain, and the Internet itself is the agglomeration of all these different networks. They'll have to work together to deliver your packets. So your computer needs to talk to all of these networks to get your data packets across. The way it does that is it becomes aware of different addresses along the way. Your laptop really does need to know about the address of the server and needs to know about the address of the next layer to hop. Then it uses that information to construct a packet. So this is how your laptop talks to the Internet. It constructs a data packet where it talks to the server in point. It tells the server, "Hey server, give me the web page for the URL, www.ilinois.edu/index.html." So it needs to tell the server what to do. But before it can do that, it needs to talk to the network interface at the server. It needs to get packets there. So it needs to tell the Internet about that location, and it does that at layer 3. So the laptop also needs to talk to the Internet and needs to say, "Hey Internet, please send my server request to IP address 10.7.18.96. But it can't just talk to the Internet. The first thing has to do is it has to talk to his Local Area Network. It has to tell us Local Area Network how to reach the Internet and it does that at layer 2. So at layer two what it's going to say is," Hey Local Area Network, send my Internet request to MAC address 9C-EF-D5-FD-27-77. So you're left up needs to do all these things to make the request go across. So to really understand this, let's look at each of these layers in turn. Because your laptop doesn't actually write "hey server" in the packet. How does it format this data? Let's inspect this. Let's start with layer 7. So at layer 7, in this particular example, we're running an application protocol called the Hyper Text Transfer Protocol. So if you use a web browser, your web browser translates your requests, all these clicks and reloads and things like that, into Hyper Text Transfer Protocol requests. The purpose of hypertext transfer protocol or HTTP, is to tell a web server what to do. So for example, suppose you have your browser open and you're browsing msnbc.com or some other site. So to do this, your browser will create a GET request, an HTTP request where it request the web page. This request has three parts: First, there's a command. It tells the server what you want to do. This is called the HTTP method. It is a short instruction which tells the server what you want it to do. Do you want to download a web page? You want to push a web page up there? What you want to do? The second part of the request is the URL. It's the resource you're referring to. In this case, we're downloading a file called index.html. The third part of this is the HTTP version. So there's different versions of HTTP and you need to tell it what version you want when you're downloading. So this string which is sent in plain text is called the client request. Is an HTTP request, it goes over the Internet, reaches the server, and the server will reply back with a response, and that will have two parts; it will reply back with the version that it's using of HTTP, and a response code. The response code will indicate maybe 200 OK, which means that you're sure that can give you that page. It might reply back with 404, which means there's no web page at that address. It may reply back with different error codes. So if you ever on Reddit and you see that page pop-up that says server overload, that's one of these codes that comes back. So there's different codes that can come back that indicate the status of the request. In this case, we've got a 200 OK. So the server is fine with us getting the web page. So it's going to send this response back and then it's going to immediately start streaming HTML, which is an encoding of the web page. Your browser reads this encoding, and then it can display the web page on the screen.