Creating a Web Server from Scratch in C

  Переглядів 50,984

Eric O Meehan

Eric O Meehan

День тому

A practical example of creating a web server in C. Unlike most tutorials, this is a web server I intend to put into production and host my own website. Additionally, I want this server implementation to be useful for any kind of server, so I will be adding it as a component in my open source C library, hdelibc, which is available on GitHub:
github.com/HomoDeusOfficial/h...
0:00 - 0:56 Node Update
0:57 - 2:49 Bad Techniques
2:50 - 7:52 Server Struct
7:53 - 14:07 Server Constructor
14:08 - 21:25 Sockets
21:26 - 31:32 Testing
31:33 - 45:59 Debugging
46:00 - 47:43 Demo

КОМЕНТАРІ: 64
@atefehz6606
@atefehz6606 Рік тому
I'm very poor and I have an old PC but I love programming . I thought maybe if I use c I can become a really good developer ^_^ thank you 😊 this is life changing for me
@GabrielxC
@GabrielxC 5 місяців тому
Hey good luck, where are you from?
@nsrc9583
@nsrc9583 Рік тому
This showed up on my feed and it was great watching this over dinner. I haven't touched C since undergrad (been with Haskell for I don't know how long now) and it's refreshing to watch some good, honest C code. I hope you continue making videos this coming year, you're great at presenting and it's clear you're experienced. Will share your channel for a boost.
@whatever6223
@whatever6223 3 роки тому
This is absolute gold! I'm going to go over this super thoroughly after I'm done with data structures
@eom-dev
@eom-dev 3 роки тому
Thank you! I'm going to be building and hosting an actual web site on top of it through the series too. Hopefully, once finished, I will have a functional website and a framework you can use to host your own website much easier. (That is, if you don't build your own version first!) By the way, the code is available on GitHub if you would like to take a look. The link is in the description, but you will need to switch to the working branch once there! Let me know if you have any questions along the way!
@koool56
@koool56 2 роки тому
Wow, in first 3 minutes you already grabbed my attention by explaining overuse of OOP like no one else
@rauldeandrade
@rauldeandrade 3 роки тому
How do you not have a million subscribers is beyond me! This is really great subject. Practical C tutorials are like diamonds. Super valuable and in short supply. Keep going. You're awesome
@eom-dev
@eom-dev 3 роки тому
Thanks Raul! I really appreciate you saying that :)
@Tabvn
@Tabvn Рік тому
That is why professor salary is less than singer or comedian :D but the true, if we do video for higher skills that is not for everyone.
@exploitingcodes756
@exploitingcodes756 Рік тому
Completely agree with this comment
@user-qe2dg8wz2h
@user-qe2dg8wz2h 7 місяців тому
God bless, I'm a beginner but the sequential teaching makes everything looks as though I was a pro.😂😂🎉❤❤
@grimvian
@grimvian Рік тому
Respect for doing the sometimes stressfull debugging on video. Having a ok understanding of C++, C and networking, I think it is a great video. Where do you get the sys/socket.h and netinet/in.h from? Do these h files have the ping facility?
@serebbi
@serebbi Рік тому
Bro, C code is so clean!!!! I love it.
@alexbraatz1431
@alexbraatz1431 Рік тому
Good stuff Eric, thank you
@thisisnotok2100
@thisisnotok2100 2 роки тому
Very cool project! I love low level stuff.
@alexandereckert4209
@alexandereckert4209 Рік тому
What a cool tutorial! Thank you so much! Like seriously
@ronen124
@ronen124 2 роки тому
43:11 I enjoyed the keystrokes sound over your keyboard
@vaibhavshinde5703
@vaibhavshinde5703 3 роки тому
This video is gem. Thank you for this nice video
@eom-dev
@eom-dev 3 роки тому
Glad you enjoyed it!
@nickodimcherepanov8895
@nickodimcherepanov8895 Рік тому
38:00 I think the right solution for the console output would be "flush" function fprintf(stdout, "message"); flush(stdout); to force it printing the message. stdout is bufferized.
@adamlabus9979
@adamlabus9979 6 місяців тому
A couple of things: 1. When declaring a const string you should make it an array, ie. not: 'char * hello = "something"' but 'char hello[] = "something"'. That makes it so you don't have to use strlen but sizeof, which is compile time. 2. Why are you putting the result connecting address of the client into the address of the server in accept?
@AlFredo-sx2yy
@AlFredo-sx2yy 7 місяців тому
Hey i know this is an old video and it might be unlikely that you reply to me, but i have a question to ask you now that a few years have passed. I don't know if you are aware of Beej's guide to network programming in C, but basically pretty much everyone says it's the best way to learn network programming in C. In that guide tho, he uses stuff such as getaddrinfo and addrinfo instead of hard coding the information inside of sin_addr. People say that this is the preferable way to program nowadays, but most production code you can find and even code on git make use of the old method so... my question is, what is your take? is it actually better to use the old school method?
@zaidshaikh750_
@zaidshaikh750_ Рік тому
After writing this server can we put our website on it. Or need something else.
@fgclue
@fgclue Рік тому
Thanks!
@minidupasan1520
@minidupasan1520 3 роки тому
Is this project needs any additional files from ur previous videos? since I am getting an file not found error for #include and #include . Please help me with this issue.
@eom-dev
@eom-dev 3 роки тому
Are you using Windows? You'll need to use winsock instead of socket.h. I don't know much about the library, but someone on the Discord channel may be able to help!
@minidupasan1520
@minidupasan1520 3 роки тому
@@eom-dev I am using windows. Please how can I join to the discord
@eom-dev
@eom-dev 3 роки тому
@@minidupasan1520 Here is a link: discord.gg/PTWecyAbDU Specifically, I think catsanddogs has done something with winsock, but I could be mistaken.
@minidupasan1520
@minidupasan1520 3 роки тому
@@eom-dev Thank u. Please If u can in the future when making such great stuff please consider windows users too, I meant to mention any changes required to make in source code who are on widows. I wish u more likes and subscribers
@eom-dev
@eom-dev 3 роки тому
@@minidupasan1520 Thank you, I appreciate it! To be honest, I think you might want to take a different perspective on this though. Unix is dominant in this space, and I would recommend using a VM of Ubuntu, an old laptop with Linux, or a Raspberry Pi when working on these kinds of projects. These are highly marketable skills - but Windows doesn't speak the same language as everyone else.
@abdox86
@abdox86 Рік тому
29:21 This is supper late , but u asked about if there's a cleaner way to print strings/arrays/pointed string , you can use puts(char* ), as it spouse to print a char* type. usage , puts(buffer);
@Brad_Script
@Brad_Script 4 місяці тому
I think the http standard expects " " for new lines
@AJ213Probably
@AJ213Probably 2 роки тому
I assume its called ipv4 because 2^(4+1)=32 and ipv6 cus 2^(6+1)=128
@guitar300k
@guitar300k 8 місяців тому
I make winsock2 version, the connect is fine, but chrome make several requests to server, it make the response sometime can't reach, anyone have any idea on this?
@azaktivalasienergiaendoter814
@azaktivalasienergiaendoter814 5 місяців тому
same
@deepakmaharana125
@deepakmaharana125 29 днів тому
bro is genious
@ArshdeepSingh-vf2zl
@ArshdeepSingh-vf2zl Рік тому
I don't know how to host an HTML file which has an img tag inside it Please Help
@AleemKhan-li3mr
@AleemKhan-li3mr 2 роки тому
hello eric can you please tell me how can i write my self server i mean what languages and concepts should i learn in order to understand each and everything and able to write server. kindly refer materials and books from where i can learn all these. thank you.
@eom-dev
@eom-dev 2 роки тому
Hi Aleem, it is really going to depend on what kind of server you are trying to set up. Generally speaking, there is probably a pre-built package for what you are trying to set up, so you may have better luck asking in their respective communities. If you are interested in network protocols, then my videos may be more useful to you. I would recommend starting by looking at the HTTP protocol and TLS.
@AleemKhan-li3mr
@AleemKhan-li3mr 2 роки тому
@@eom-dev thank you so much for replying i really appreciate it. it would be very appreciated if you can make video and speak about these things so many other would benefit from that like new guys to computer science like my self. thank you once again.
@StandardLoop
@StandardLoop 2 місяці тому
Nice
@morritz5548
@morritz5548 2 роки тому
Content-Length is mandatory header, it should be kept
@illegalsmirf
@illegalsmirf 3 місяці тому
Have you tried using PHP?
@MurderByProxy
@MurderByProxy 5 місяців тому
11:23 im not that seasoned in neither c/c++ but couldn't you call the constructor variable domain as well and then just this->domain = domain? //well only if its a class and I'm already exited there is a cpp one lol
@loganmahoney2284
@loganmahoney2284 2 роки тому
"Oh yeah it never works the first time" :D
@nickodimcherepanov8895
@nickodimcherepanov8895 Рік тому
The definition outside of the loop is not a solution at all. There is not a lot of work, especially for a MacBook. Stack allocated memory is extremely cheap in terms of speed.
@parikshitpatil1421
@parikshitpatil1421 Рік тому
One of the best way of doing debugging is print statements. 😂😂😂 Me too. But on stderr not stdout.
@helloworld-fv8kx
@helloworld-fv8kx 2 роки тому
how to make https ?
@sebastianguzman7391
@sebastianguzman7391 2 роки тому
About printf("==== WAITING FOR CONNECTION ====") not works is because printf is LINE BUFFERED that means the printf needs ' ' or the program ends to sends the current buffer to processor to be shown in the screen, grettings from Ecuador :D. I love your channel.
@yapdog
@yapdog Рік тому
I'm just curious: why don't you use typedef struct? It's save you a lot of typing.... And, why don't you copy/paste your prototypes to avoid all of the typing and potential bugs?
@GarrethandPipa
@GarrethandPipa 2 роки тому
ipv5 was never adopted as the standard hence why we ignored it
@eduardabramovich1216
@eduardabramovich1216 Рік тому
that white background is killing my eyes!
@protyaybanerjee5051
@protyaybanerjee5051 2 роки тому
What IDE is this ?
@zainebqadiri5155
@zainebqadiri5155 2 роки тому
xcode
3 роки тому
Can I get your source code?
@eom-dev
@eom-dev 3 роки тому
You may! github.com/HomoDeusOfficial/hdelibc/tree/working
@alexantollin564
@alexantollin564 5 місяців тому
https server? ssl tls considered
@zevexerity1208
@zevexerity1208 2 роки тому
Bro did you not know you need ... or you could do flush(stdout); for printf xd
@mounir434
@mounir434 2 роки тому
too bright my eyes hurt
@eom-dev
@eom-dev 2 роки тому
lol I would agree with you these days.
@swedishpsychopath8795
@swedishpsychopath8795 3 місяці тому
You've misunderstood. You are clearly using .cpp files instead of only .c files. C++ is not the same as C. Sorry to be the one to tell you.
Web Server Concepts and Examples
19:40
WebConcepts
Переглядів 221 тис.
How one thread listens to many sockets with select in C.
12:01
Jacob Sorber
Переглядів 93 тис.
Making Simple Windows Driver in C
7:26
Nir Lichtman
Переглядів 266 тис.
coding in C but I start over for every compiler error
16:34
Low Level Learning
Переглядів 262 тис.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Переглядів 314 тис.
Making Minimalist Web Server in C on Linux
10:23
Nir Lichtman
Переглядів 185 тис.
Building a Web Server in Rust - Part 1
16:19
Let's Get Rusty
Переглядів 80 тис.
Why i think C++ is better than rust
32:48
ThePrimeTime
Переглядів 258 тис.
Writing My Own Malloc in C
2:07:13
Tsoding Daily
Переглядів 194 тис.
Your Old PC is Your New Server
11:07
Linus Tech Tips
Переглядів 6 млн
Добавления ключа в домофон ДомРу
0:18
Vortex Cannon vs Drone
20:44
Mark Rober
Переглядів 13 млн
Рекламная уловка Apple 😏
0:59
Яблык
Переглядів 731 тис.