This tutorial provides a lucid return to first principles, demystifying the foundational "plumbing" of the web that modern abstractions often obscure. It is a vital exercise for any developer seeking to master the raw mechanics of network communication rather than just consuming high-level frameworks.
深掘り
前提条件
- データがありません。
次のステップ
- データがありません。
深掘り
C Basics HTTP Server追加:
We're going to be doing writing our own C networking server. Well, an HTB server. Very simple HP server. We should be able to get through it pretty quick.
I think we should be able to get pretty quick. I'm pretty certain. What do you read HTTP as or what does HTTP stand for? Hypertext transfer protocol, right?
Isn't that what it is? I should know. I have a whole I like depend on it. Isn't it hypertext transfer protocol? I've got our got our uh our Linux pages up here.
our man pages for our socket socket stuff. So, I was going through that a little bit before stream started, right?
Isn't it? HTTP stands for uh hypertext transfer protocol. Hey. All right, there we go. HT lowerase T capital T and protocol. Hypertext transfer protocol.
Thank you. Oh, yeah. All right. So, let's see if we can get some some stuff.
So, I know we're going to need to include socket.h. I think we need to also include an inet. Here we go. We need to include this as well. So, we got a couple of things to include here. And then we can start getting our HTTP server started. I'm excited about this.
This is what my whole business is based on. This these lines of code that you're about to see are worth that worth so much to me and have done so much over time. I'm really excited about it. It's pretty neat. It's IO.h. And then we also need some sockets in here. We need some sockets. include inet in probably that I'm pretty sure maybe. And then we also need a socket. I'm pretty sure we need a socket. Here we go. It says sockets.
Perfect. Here we go. There we go.
Getting them in. All right. So, here's our networking stuff to be doing some socket programming. Here we go. All right. So, what do we need to do here?
Let me let me look over this. All right.
So, I know we're going to have to define a port and a couple of other things. A socket. socket. There's got to be a method in here. Here it is. Here it is.
This is what we need. We need this. All right. And then we're going to need some of these guys. Some of these some of these constants in here. Uh here we go.
Right. Socket file descriptor. Perfect.
Perfect. We need this. That's going to have to have to be that. I know we're going to need that. Uh and then we need a socket family. We need a socket type.
and then a protocol which is going to be TCP probably, right? It's going to be TCP because we're doing an HCTP server.
We're going to make it an integer. So, this will be the main the main socket uh main entry FD and then we're going to get other FDs I think with a client socket in a different port that we'll be able to accept after we after we accept it and then we'll be able to write that socket. So this is the main inbound.
This is the inbound main entry. Inbound file descriptor file descriptor FD right file descript or file descript which basically is the IO part of the operating system. It's going to it's going to be the inputs and outputs where the operating system is going to read and write bytes from. That's some I need to bind. We need to do binding next.
Bind is bind in here. Yes, there's a lot of bind. There'll be some binding and some listening and some closing and things like that. All right, so bind int bind. All right, so we need to run this.
Let's see here. We're going to add this in here.
Okay, we also need an address. I think we're going to have to do that as well.
C, we're doing C basics. Obviously, if you want to do it in Rust, you're going to have a better time or worse depending on [laughter] there could be some challenges. How is it an int? Because it is going to be a 32-bit value. It's going to be a number and it's going to be representing a number that the operating system is going to hand to us. It's basically it's like a ticket, like a line like here's your ticket, sir. Use this ticket to communicate with my with my inputs and outputs. So, this is the operating systems ticket. And then we're going to bind on that on this on this file descriptor creating. Hey Joshua, we are building an HTTP server in C. Today is the last day of C basics. We're going to get ourselves a file descriptor from the operating system asking for essentially a socket stream. Then we're going to bind our local address which is going to be 0000 a whole bunch of zeros. And then we're going to add a port to listen on for incoming file and then we'll register new file descriptors which we can communicate back and forth to individual clients. And that's the plan.
We're going to do that. That's the plan for true like this. True, which is wow.
Wow forever basically. And we'll eventually break. We'll eventually break. Uh we're going to be doing essentially we need to do we need to listen for incoming connection requests requests. And then we need to uh uh accept that request, bind it, read from it, read from the socket on the file descriptor, capture the user's request and then respond.
So there's what is TCP? It is it's like on the internet there's Ethernet frames, right? Right. So you got Ethernet frames which is like the core foundation of the communication wi-i which are packets little small packets of data that have headers which describe where data needs to go and then there's a body section and that body section is all the text like all the text that you send like you just typed your your message. Your message was the in the body section.
Transmission control protocol. Yeah, thank you Sivon. That's what that is. It is sort of like a description of how data is transferred. It's a protocol.
way. It's an exchange of information, a system and [music] a strategy between.
All right. So, we need a socket address here. All right. So, we're going to do this strct socket address. And then we need to assign ourselves a socket address. And it's going to be the same socket. It's going to be same family.
Same family here. And I think we have to do we have to do it like this? Let me double check. No, I had it right. I had it right the first time. Okay.
So, we're going to be making this, right? Because it's the family, right?
Right. The family right here. The port number. We should probably do this. Uh define define port. Well, that's probably like this, right? Uh lower case define port as port. We'll do 8 8. Well, we'll do 8 9 0 0. There's an easy port. There's go.
We're doing socket programming. And it's been a little while since I've done this, right? because once you write it things you typically work just perfectly fine and we do port I think we do port I'm pretty sure and then uh we have we need to do in address uh let's see here where is that uh okay so basically we're going to use this keyword here in any address which is essentially this 0.0.0.0 zero. That's what that is. You want it you want to accept and we're this is basically we're we're targeting anything and we're going to bind on this address. We're going to bind on 0000 on port 890 or 89 or 8,900.
That's what we're going to do. Typo there. Sorry. Oh, no worries. Hey, we figured it out. We figured it out. Great to have you guys here.
I have an obsession with people, right?
So we're talking about like uh IPv4 slash wait. So V4 SLIPv6, right? So you got those those varieties there. Address family. Got to have your address family guys. Socket stream instead of a socket data Dgram, right?
So you can do Dgrams or socket stream.
What are we making? All right, great question. We are making a HTTP server from NC from scratch as you can see here. And we're going through the Linux man pages. So you can see here we've got our Linux man page right here. I've got it over to the side so that way I can build it for you. And we're going to make sure that we get it ready and all nice and tidy and it's going to look and it's going to work good and we've got plenty of time. We've got plenty of time and we're going to keep it simple. We're going to keep it simple. So we need we also need to bind. We need to listen.
And then we need to accept. We need to bind, listen, and accept. So we do accepts here. Accept here. And then actually it's going to be like this.
Accept here. Then we're going to bind here. And we need to listen as well. We need to listen. So that way we can capture we can capture incoming requests essentially for new ports or new file descriptors. Here uh strct we'll call this our socket address in perfect. We we we could call it whatever we want.
We'll call um inbound sockets. We could we call that right. I'm pretty sure.
Right. [laughter] Right. We can do that right there. We can do that. And I think we have to do amperand. We'll do amperand. Uh and then we will do we need to have size of we need to do a size of this guy right here. Inbound socket. Okay.
Size of There you go. I think that'll do the trick. I might have to do some interesting things on this. We'll have to find out. Socket add struct. Oh, wait. Uh, one second. Uh, wait, wait, wait, wait. Inbound socket. One second.
I need this to be here. 99 redo. Okay, this will be 1 second.
Add. We'll call it server. Server address. Here we I I think server we are building HTTP server in C from scratch. People can't code without AI.
Uh just right. We an AI can't code without Steven hardwired. Thank you. And percent means address. Yes. So we're we're passing the reference the address to the structure for the bind so that way it can read the memory at that location. That's what we're doing. So I believe this part is good. I believe it's good. I might have to do a few things. Let's see here. Let me see. Uh, I'm going to comment this out here.
Well, you know what? I'll just say break. There we go. We'll say break. Uh, thank you for joining you guys. Happy to have you here. Well, LT Sun, what are you doing there, Heartwire?
That's my my first company. That's my All right. So, I think what we need to do here is we need to do some casting.
Let me double check. Let me pull open my Oops. Sorry about that. I didn't mean to blind you guys. Here we go. Here we go.
All right. I need to cast that as a as a specific data type here. All right, let's do that. Uh, right here. That like that. Wait, wait. Um, like this. There we go. I think we have to do that. I think we have to do that. It says it needs to be a sock edadder. So, right.
See, as you can see right here, look in my in my right here. Check it out. It needs to be the address of a sockadder.
Ah, there we go. And what did we just do right here? What did we just do? We did an address of a socketer. So, we're doing a cast. We're casting it because it's the same kind of str. It really is.
It's just slightly different. Maybe port is fine here. What does it say? Uh, implicit conversion from int to saw family. Unsigned char. Oh. Oh, unsigned char. Unsigned char. Okay, let's try that.
What is that? What is that? int aka unsigned char changes from 9 to 72. All right, we'll figure this out.
We'll make it happen. We'll make it happen, you guys. Uh, I need to include a conversion. I feel like that should work. Thank you for subscribing. Who is that? Who that? Uh, having fun on YouTube. Thank you for subscribing. Mo, come on in. Construct socked ender.
Thank you. Uh, so sucker in. Uh-huh.
Yep.
Uh la. Sorry, I'm gonna be off this live. Hey, Betty. Bye. Thank you for hanging out. What's the challenge? Hey, uh we are currently trying to make sure that we get uh Hton Tons port. Uh SN port. Okay, let's try. I think we need to include a converter. So, let's try that. H2 H2. Uh unsigned Char said a simple type mismatch. Yes, the macro isn't casting uh catching it, so that's why the arrow, I guess. Yeah, me too. I think so. Yeah, I think so. Like an hour. Well, we've got 30 minutes. We got We got 20 actually 25 minutes. So, we do got to get going here. So, let's let's make our way. Let's make our way, you guys. Uh what is here? Okay. Why is this highlighted? What happened? Oh, right, right, right. Okay. Right, right, right.
Okay. Uh D comment that out. tupil address family strct bind to listen. So now we should be able to get into the the rest of it here. We should be able to get to the rest of it. Okay, we're going to have another client FD. Do we have a Yeah, the socket. So this is the server FD. What I'm going to do is I'm going to I'm going to change this to server server FD like this.
There we go. So that way we know. And then we're going to have the client file descriptor here. We'll have accept and it will be accept. And I think we need to just pass in the server uh server server file descriptor or server something here. Server FD yeah.
And then we don't need anything else.
There we go. Okay. So that should allow us to accept requests.
That should allow us to accept can run HTTP. Okay. Good. Okay. Good. Okay.
Good. Okay. Good. Nice. And nice. And now all we have to do is read data. We have to read data from this file descriptor. Okay. Um so this is our um so then we can just send data. I think we can send data, right? Okay. So we should be able to send client file descriptor. Uh and then we need to say uh we we need to it needs to be HTTP response headers, right? But let's just let's just send a bunch of text back r.
Let's see what that does. That might cause a problem. An HP server use case.
A HTTP server is a way for you to create an API endpoint that you can host a software somewhere in the cloud or on a rack somewhere in one UU if you want in a colo data center. You could essentially make your own API or make your own web server. And that's what we're kind of doing right now. That's what we're doing. the back slash back rn rn uh hello world. One second. All right, I we're running out of time, you guys.
We're running out of time. Uh let me see here. Let me know if I got anything right. Steven is testing in production, I heard. Yeah, we do that sometimes, too. We've done it. We don't do it anymore. Uh looks good. Best of luck, bro. Thank you, Spicy Chips. Still under construction. You got it. I'm actually trying to uh make a rich present for Discord. And see, this is so helpful.
Hey, nice. You're trying to make it.
Yeah. Is accept blocking? It might be.
It It is. It's actually It is. Don't run late. I know. Let's build an IRC. We could You could build You could build one. You could build one. Uh, bro can make another Linux using C or Rust.
Which is would you prefer? Rust. Goku.
Do rest. Do rest. Make it rest. Uh, so let's see. Back slash Rn. Let's see. And then we say 1 2 3 and then back slash R back N. I think that should be good. And then let's do S strang on that.
Although str instead of 14.
Is that it? Is that it? Yes. Okay.
I still don't think Uh-oh.
Uh-oh. What does it want? Too few arguments. What did I What did I mess up? I I messed it up. Oh, respond. Okay.
Got it. Got it. Got it. Yes. Yes. Yes.
Okay.
Okay. There we go. Boom. All right.
関連おすすめ
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











