字幕表 動画を再生する 英語字幕をプリント [MUSIC PLAYING] DAVID J. MALAN: This is CS50. And today, we transition from the world of C and, with it, pointers and some of the struggles that you might have felt over the past few weeks to a more familiar world, that of web programming. I'm using web browsers and mobile devices and laptops and desktops and creating more graphical and more interactive experience than our traditional command-line terminals have allowed. And we'll see, though, along the way that a lot of the ideas that we've been exploring over the past few weeks are still going to remain with us. And we're going to see them in different ways. We're going to see them in the form of other languages and other syntax. But the ideas will remain quite reminiscent of what we did back in week 0. So TCP/IP is perhaps the most technical way and the most low-level way we can quickly make the web uninteresting. But you've probably, at least, seen this acronym somewhere, maybe on your Mac, your PC, some setting maybe once upon a time. And this, actually, just refers to a protocol or, really, a pair of protocols, languages of sorts that computers speak in order to transmit information from one computer to another. And this is what makes most of the internet today work. The fact that you can pull up your laptop and desktop and talk to any computer on the internet is because of these protocols, conventions that humans decided shall exist some years ago. And they just dictate how computers intercommunicate. But let's make it a lot more familiar. In our human world, you've probably, at some point, sent or received a letter. These days, it's perhaps more electronic. But, at least, you've gotten one such letter from probably a human, maybe a grandparent or the liked, or sent something yourself. But before you can actually send that message to the recipient and put it through the US mail or the international mail services, what needs to go on the envelope? AUDIENCE: Address. DAVID J. MALAN: Yeah-- so some kind of address. And what does an address consist of? AUDIENCE: Name. DAVID J. MALAN: Name. AUDIENCE: Where they are. DAVID J. MALAN: Where they are. AUDIENCE: [INAUDIBLE] DAVID J. MALAN: So where they are might include a street address and a city, a state, a ZIP code in the US, or a postal code, more generally, and the country, if you really want to be specific. And so all of that goes on the front of the envelope, generally in the center of the envelope. And then what often goes on the top left-hand corner in most countries? AUDIENCE: The return. DAVID J. MALAN: Yeah. So the return address-- so that if something goes wrong, albeit infrequently, that letter can get-- make its way back to you, and also the recipient knows just immediately who actually sent them the no. So that is enough information to get a letter from point A to point B because these addresses, these postal addresses in our human world, uniquely identify houses or buildings or people, in some sense, in the world. So right now, we're at 45 Quincy Street, Cambridge, Massachusetts, 02138, USA. That is probably enough specificity for anyone in the world to mail us a postcard saying "Hello world" in written form and get it to this building. Meanwhile, if we wanted to send something to the Science Center, 1 Oxford Street, Cambridge, Mass, 02138, USA, that's its unique address. So it stands to reason that computers, including our own Macs and PCs and Android phones and iPhones and the like, all have unique addresses, as well, because, after all, they want to communicate. And they need to get bits, zeros and ones, from point A to point B. But they're not quite as verbose as those kinds of addresses. Computers have what you probably know as IP addresses, Internet Protocol addresses. And this just means that humans decided years ago that every computer in the internet is going to have a unique number identifying it. And that number is generally of the form something dot something dot something dot something. And, as it turns out, each of these somethings between the dots is a number from 0 to 255. And now, after all these weeks of CS50, your mind can probably jump to a quick answer. How many bits must each of these numbers be taking up if the range is from 0 to 255? Eight. So eight-- and why is that eight? So 256 has been a recurring theme. And if you don't recall, that's fine. But yes, this is eight bits, eight bits, eight bits, eight bits, which means the numbers that we humans use to uniquely identify our computers on the internet are 32 bits in total. Well, there's probably another number that can roughly come to mind. If you've got 32 bits, how high can you count, roughly speaking, from 0 to-- I heard a murmur-- AUDIENCE: Four billion. DAVID J. MALAN: Four billion. So it's roughly four billion. And we brought that up in week 0 with a four billion-page phone book, imagining that. So four billion is roughly what you can count up to with 32 bits. So that means there can be four billion computers, devices, or anything on the internet, uniquely identified-- small white lie because that's actually not quite enough these days with all the devices and all the humans in the world. But we found workarounds for that. Question? AUDIENCE: [INAUDIBLE] DAVID J. MALAN: But only half of them at the time. No. So yes, if by 2023 or whatever year humans are projected to be almost entirely online, and there's some-- billions and billions of people, eight billion or so, then that's a problem for this system. Thankfully, as long ago as 20 years ago did people realized, mathematically, this was going to be a problem. And so there's actually a newer version of IP, Internet Protocol. This is version 4 we're talking about, which is still pretty omnipresent in the world. Version 6 actually uses not 32 bits, but 128 bits, which is massive. And I can't even pronounce how big of a number that is. So we're thinking about it. And the biggest companies of the world have already transitioned to using bigger addresses rather than these 32-bit addresses. But these are still pretty common in almost any device you might own or see on campus or elsewhere. So if you have a unique address, that's enough to put on the front of the envelope. And it turns out that if you're sending an email or a chat message or whatever, you, too-- your Mac, PC, or phone-- has an IP address. So that's enough to put in the top left-hand corner, conceptually. But you need one more piece of information. It turns out that on the internet, there are servers, computers, that are just constantly listening for people to connect to them, like us, checking our email and visiting Facebook and Gmail and other such websites. And those servers, though, can do multiple things. Google has lots of businesses. They give you email and web services and video conferencing and lots of other internet-based services. And so humans also decided, years ago, to identify all of these possible internet services with just unique numbers-- names also, but also unique numbers. And it turns out that humans decided years ago that when you visit a website, there's one more piece of information that's got to go on this envelope, not just the server's IP address that you're trying to connect to, but also the number 80 because 80 equals HTTP, acronym you're surely familiar with by now. And that just denotes this is a web request. If, instead, it said something like 25, that's SMTP, which is email. So that might mean inside of this virtual envelope is actually an email message going to Gmail or the like. And there's bunches more numbers. But the point is that there are numbers that uniquely identify. So when Google gets a virtual envelope, just a whole bunch of bits, zeros and ones, that, in some way, has an IP address on it as the destination, it also knows, oh, is this an email or is this a video conference message or is this a chat message or something else. So just to make this more real then, if I'm going to go ahead and write this down, my IP address to whom I'm sending something might be 22.214.171.124. Generally, then, I'm going to send it to, say, port 80. Maybe my IP address is 126.96.36.199. And so an envelope-- I'll be at [INAUDIBLE]---- and it's really just going to have those pieces of information-- the destination address, colon, and then the number of the service you care about, HTTP or whatever, and then your own IP address, and more information. But the point is both sender and recipient in dresses-- that's enough to get data from one computer in the world to another.