 Hey everybody, it's Brian, and welcome to the 63rd Qt tutorial with C++ and GUI programming. Today we are not actually going to write any code. Today we're going to begin a primer for network programming. So if you're already a networking guru, go ahead and skip this video. However, if you've never done any network programming, it'd be a good idea to pay attention. We're going to go through this fairly quickly, and I'm going to try and condense probably about two or three weeks of college classes into about 15 minutes. So if you don't understand what I'm talking about the first time, rewind the video and rewatch it, and hopefully it'll sink in. All right, now you all know how to surf webpages. I mean, you're on YouTube, so I imagine you know how to get from point A to point B. But do you understand how that really works? Well, in order to do that, you have to go through a series of networks. And let's just go to Google Images. I'm just going to show you a couple of things. One thing it uses is called TCP, or transmission control protocol. And you can see how it's got this little image here of these computers, and it goes into these little networks, and it chains around. That's actually how the internet functions. When you send a message from point A to point B, it doesn't actually go from point A to point B. It goes through all these little networks and circuits and gobbledygook out on the internet. Little out of the scope, I just wanted you to understand that there's a whole network, and there's a big mesh of networks that has to function together. There's two types of protocols you're going to be working with. There's TCP, and what that means essentially is you are creating a connection. TCP has a three-way handshake, and the three-way handshake is basically a you send a SIN packet, then you get a SIN AC response, and you send an AC packet back. Now that happens transparently. You don't see any of this going on, but you should know that when you use TCP, there's an actual handshake and a connection. So you verify there's a circuit there. Now there's UDP, which I don't know if we can even really find a reliable graphic for UDP, but we'll try. Whoops, USD. Don't want that UDP. Yeah, this is probably a pretty good representation right here of the difference. With TCP, we have a connection with UDP. It's connectionless, meaning you just fire the data off and forget about it. You don't even know if it ever reaches the destination or not. Why would you want something like that? Well, UDP is much faster because it doesn't have that overhead of the three-way handshake. Now, as you can imagine, no, the internet would not function very well with UDP because you need that reliability of that connection. You need to know when the connection is dropped. You need to know if the data is corrupted or just doesn't make it there. One other thing you should note is DNS. Let me pull up this graphic here and this is kind of look very unfamiliar to most of you. What is DNS? Well, when you type in Google.com, that's DNS. Basically, DNS translates an IP address to a friendly name. For example, when you go to Google, and let's just try to find... Let's just find who is. Who is Lookup will tell us who owns something. Let's just go here. Who is and just type Google.com. You can see Google.com and all the information about it. You can actually contact customer support. You can view their IP ranges. Here's their name servers. Now, what's a name server? Well, that goes back to DNS. What that means is when you type Google.com, it's actually going through the root server and then it's going to the .com server and there's actually a group of these servers. It's not just one server in a basement somewhere. And then it says, okay, who owns Google? And then it forwards it over to Google's name servers. And then one of these guys right here, NS1 through 4, picks it up and says, okay, where do you want to go within Google? So, you know, kind of go out and play with who is Lookups and figure out, you know, who owns what. Now with that, I'm going to pull up a command prompt here. And if you don't know how to do this, just go start run, type CMD and hit enter, and that'll bring up this command window. And you're going to learn some basic networking commands. For example, if you type in IP config and hit enter, you'll see a whole lot of information here. And you see, I have an IP version six address and an IP version four address. Now, what's the difference between these two? You know that the IP version four is much smaller and probably similar to what you're used to seeing where the IP version six is much bigger. Well, we're running out of IP version four addresses on the internet. So we're all slowly transitioning to IP version six. Now, you should note, this is not my actual IP address on the internet. This is my local IP address. Remember that TCP diagram we had? Let's see if we can pull that up again. So this would be my computer. This would be my home router. And then this would be my ISP, in this case, Comcast. And that forwards off to, you know, who they're chaining through. And then it goes through this mesh. And there's a whole bunch of protocol and gobbledook that happens in here. And then eventually gets to the endpoint. Now, this default gateway 192.168.111. That is actually my router. It's called a gateway because it acts as a door to another network. Think of like, I don't know, I'm probably dating myself when I say this, but think of the Twilight Zone series, how it has that mysterious door standing out in the middle of the network. Well, that's kind of what a gateway does. It allows you to go into another network. And let's actually pull up a picture of a router here, just in case you've never really seen one or you don't really know. And I'm sure you've seen a couple of these, these little guys right here, these routers. And what these do is they route traffic. That's quite literally all they do is route traffic. So you send traffic to it through this TCP. And then you say, okay, I want to go here. I want to go there. And then it just does what it needs to do. Whoops, lost my command prompt there. And let me bring this back up here. Sorry about that. It's been an incredibly long couple of days. My poor cat that some of you have been asking about passed away. So didn't sleep very well last night. All right. There we go. So that's how you find your IP address. And note, you can have multiple IP addresses on the same machine. Now an IP address is just an address. Don't get hung up on the term IP. It's just an address. It's like, it's like a post office address. It's like a zip code. It's like a telephone number. It just says where on the network are you? That's all it means. Now one thing we should cover is go back to DNS, do NS lookup and do google.com. This is what happens when you go to a webpage. You perform an NS lookup if you haven't already. It's all done automatically. You contact your DNS server. In my case, it's this westlandsmichigancomcast.net and there is the address space for google.com right here. So what it does is it says, okay, are you busy? Yes. Are you busy? Yes. Are you busy? No. Okay. Make your connection. That's what I mean by you can have more than one IP address. Now google.com is not one computer sitting at some guy's basement. It's a massive network. So we're actually only seeing a very small segment based on the region that we're in. So that's what I mean by IP address. Let's actually take one of these guys. Let's just take 19 right here. Let's pull up a web browser. And instead of going google.com, let's just go to that IP address. Sure enough, it brings up google. So when you go to dub dub dub google.com, it's actually doing an NS lookup in the background and saying, okay, what's a free address for google? And it gives you the 74.125.225.19. How'd you like to type that in every time you wanted to go to google? What a pain. So that's what DNS does. It allows you to say, you know, like mywebserver.com or .org or, you know, whitehouse.gov. That's how that works. Now, the other concept that's very important is the concept of ports. What are ports? Well, you can have multiple addresses. Each address can have multiple ports. And what do I mean by that? A port is a channel that you can connect to and communicate with. For example, the most common port for web servers is 80. And let's do a netstat-n here. And you can see these right here. Actually, these guys down here. Notice that's Google's IP range, 74.125.225. Same thing is up here with this colon and then 80. The colon denotes that you're calling a port. So we're calling port 80. And the state is established, meaning we've established a connection. And I've got my web browser open. So if I close that, it'll close those connections in the background. Now, you notice how there's also a port on your local side. Here's my IP address 192.168.1.132 colon 49593. You don't need to know what any of this is. You just need to understand that your computer has an IP address. Each IP address has multiple ports. In order to connect to another computer through, you notice the protocol's TCP, that connection, you need to have a local IP address in a port and a remote IP address in a port. Now, when you're programming, most of this is done in the background. All you need to know is what do you want to connect to? What do you want to send? What do you want to receive? That's all you need to know. But I wanted to kind of go through this primer really quickly, because a lot of people that are good at programming have never touched networks. They have no clue how networks actually function. And I think that if you're going to be a good programmer, especially with networking, you really need to understand this stuff. And kind of point in case here, if we just go to planet-source-code.com and just go to the dot net section, I realize we're covering C++ here. And search for my handle, which is void realms. And scroll down here. If you know any dot net whatsoever, you can kind of browse through some of the source code that I've submitted. Planet-source-code is just a contest website. People submit their source code for a peer review and contest. And I've won a lot of these contests. But I've actually created like a threaded HTTP download in vb.net. And you know, I've done from scratch an FTP server and HTTP server and FTP client, you know, et cetera, et cetera. And I've won this award a few times. But so if you're into dot net, you can go out and download and review this. And we're going to be doing some of these. Qt is very, very good at this. That's one thing I really like about Qt is how they handle networking. That's not as convoluted as a lot of the other languages that I've seen out there. But anyways, I wanted to show you Planet-source-code to show you that, yes, I indeed do know what I'm talking about. And I have been doing network programming for a long time. And it's challenging. So don't get frustrated. You just have to know how things work under the hood. Anyways, I'm babbling. This is Brian. Thank you for watching. I hope you found this video educational and entertaining.