I Wrote HTTP "From Scratch" (It Was Easy)

  Рет қаралды 48,917

Sean Bix

Sean Bix

Күн бұрын

Link to the project: github.com/Bixkitts/relic-mer...
(It's a multiplayer browser game)
Link to newb-friendly article: developer.mozilla.org/en-US/d...
Link to actual HTTP 1.1 standard: www.rfc-editor.org/rfc/rfc2616
Note: I wrote HTTP 1.1, not 2 or 3 or even TCP/IP itself.
BUT this does include TLS/SSL.
Blocked nose today, sorry.
I'm happy to answer any questions in the comments pertaining to HTTP basics, stuff I missed, corrections, or the project!

Пікірлер: 71
@lukeh990
@lukeh990 14 күн бұрын
You know it’s going to be a good video when it starts out with: “We’re going to assume the presence of a TCP/IP implementation on your system”
@Ginto_O
@Ginto_O 4 күн бұрын
well i mean it is preinstalled on windows but you know how to install it right? in network properties
@Q_20
@Q_20 15 күн бұрын
I read that as C written in HTTP, and was hoping for next level black magic shit.
@seanbix5366
@seanbix5366 15 күн бұрын
If anybody is determined to bless the world with this, I'll help where I can!
@vpd825
@vpd825 10 күн бұрын
Same here 😂 This is still cool.
@shinej11
@shinej11 14 күн бұрын
I spend most of my time with Python, with all the layers of abstraction. This video definitely rekindled my love for C. Thank you.
@seanbix5366
@seanbix5366 14 күн бұрын
@@shinej11 Python's is imo the least evil scripting language, and can do some low level stuff too. I once implemented some serial networking protocols in Python on a microcontroller. Use the right tool for the job and have fun!
@syedsaifuddin1413
@syedsaifuddin1413 15 күн бұрын
Ahh very good explanation good sir. I was getting into c socket programming without understanding the underlying fundamentals to implement this protocol. Gained a lot of information from this one.
@shreeyashpandey3530
@shreeyashpandey3530 15 күн бұрын
That's a very creative way to use gimp as a presentation tool! hella based video!
@impaglg
@impaglg 11 күн бұрын
Thank you for this video Sean! it really was eye opening.
@whonehuljain
@whonehuljain 15 күн бұрын
Great content, also amazing explaination!
@s1ckret
@s1ckret 16 күн бұрын
Great work, man!
@iSam36O
@iSam36O 13 күн бұрын
moonfly gang 🔥 great video btw, keep them coming!
@prashlovessamosa
@prashlovessamosa 14 күн бұрын
Wow great learnt a lot keep uploading good stuff.
@JeremyAndersonBoise
@JeremyAndersonBoise 14 күн бұрын
This is a great practice project for programmers. Very cool moves.
@SamirPatnaik
@SamirPatnaik 16 күн бұрын
S+ tier content
@SalirDeMatrix
@SalirDeMatrix 14 күн бұрын
You are a good developer. 👍
@bennguyen1313
@bennguyen1313 15 күн бұрын
Any thoughts what would be involved in writing an ESP32 application, that takes data from the uart, and passes it wirelessly either bluetooth (SPP) or via Wifi. For Wifi, I imagine the ESP32 could act as a web server (TCP) and display the RS232 data, but maybe there's a UDP way it could send data to a PC on the same network?
@seanbix5366
@seanbix5366 15 күн бұрын
Oh for sure. You take your UART data, format it into a buffer and you can make it available over TCP with HTTP just like I've done here. Doesn't even need to be HTTP/webserver! Only if you want to load it in a web browser! It's probably easier to have the ESP32 be a TCP client that connects to the PC acting as a TCP server (HTTP or not). UDP is likely to be even simpler, depending on your needs. I've done a lot of Arduino programming, it'll likely have libraries to make all this easy enough!
@justcurious1940
@justcurious1940 16 күн бұрын
Is the operating system involved in the TLS protocol or the OpenSSL library will take care of encryption and the decryption of the data and then just use the send and recv functions provided by the OS ?
@seanbix5366
@seanbix5366 16 күн бұрын
That's abstracted away by the library such that it's simple. The operating system is involved in the protocol, such that the library that implements the protocol, interfaces the operating system for various utilities to assist it in doing so. Encryption algorithm: library code Reading a certificate file: OS code So yeah its more than likely that it (openssl code) encrypts the data before just sending it over send().
@justcurious1940
@justcurious1940 15 күн бұрын
​@@seanbix5366 Thank u for clarifying this. Good luck with what ever u are doing today or u are planing to do tomorrow 🙃.
@DanielPopsuevich
@DanielPopsuevich 15 күн бұрын
Execllent video! Just what I was looking for. I recommend thinking about a better title in future in order to attract more viewers to your content since this video is a fantastic deep dive, you explained protocols in less than a minute visually.
@user-lv5vj1vo9t
@user-lv5vj1vo9t 14 күн бұрын
How different is this from the binary HTTP protocol? And can you leverage your code into that easily?
@seanbix5366
@seanbix5366 14 күн бұрын
I literally googled HTTP RFC and immediately started writing the code. I was roughly today years old when I saw there was http 2 and 3 so I don't know yet 👉👈 I've heard they're the same protocol, but with a binary format and extra features, so it should be doable!
@DailyFrankPeter
@DailyFrankPeter 14 күн бұрын
In the worlds of Linus Torvalds - let's write it from scratch; how hard can it be!
@andregeraldo6556
@andregeraldo6556 13 күн бұрын
just got smarter watching this lol, good video
@fabienWendpanga
@fabienWendpanga 16 күн бұрын
Very interesting! Now, i am wondering as a c# developer is it something i cam replicate? Also do you have it on a repository ? Thank you very much
@seanbix5366
@seanbix5366 16 күн бұрын
Yes, and yes. This is "socket" programming, the operating system's abstraction of TCP/IP which you can do in C#. That's how you would send the HTTP header string and data. This is purely for learning purposes though, it's not massively practical or idiomatic. C# has easy HTTP interfaces. The project is linked in the description!
@Alfred-Neuman
@Alfred-Neuman 6 күн бұрын
Next step is to write HTML from scratch, and then Javascript... Good luck! 😀👍
@AndrewNijmeh
@AndrewNijmeh 14 күн бұрын
this is how real men program 🙏🏼
@grenadier4702
@grenadier4702 14 күн бұрын
Maybe I didn't notice but have you tried using non-blocking event-driven i/o? As far as I remember it's the fastest way to handle requests
@seanbix5366
@seanbix5366 14 күн бұрын
@@grenadier4702 All of my sockets are "non blocking", but they block anyways (lmao) because each connection is accepted in its own thread. TCP multicasts make full use of non blocking IO on one thread through. All file reads are lazy loaded and cached into memory with mmap so its eh, good enough on that front I guess. Not a hash map or event queue in sight, just a simpleton, liberally mutex locking.
@grenadier4702
@grenadier4702 14 күн бұрын
​@@seanbix5366 Yeah, I see now. Here, right? while (er == RECV_TRYAGAIN) { er = tryAcceptConnection (localhost, remotehost); } You're basically looping until an error or a connection arrival? And here in each thread you just check for blocking and repeat the same loop again? else { if (errno == EAGAIN || errno == EWOULDBLOCK) { continue; } fprintf(stderr, " Socket error, closing connection... "); closeConnections(args->remotehost); } But why do you need non-blocking sockets here at all? When you accept a connection, if it would block, you repeat the same loop again so it's the same as a blocking socket. In second code block, it;'s the same thing: even if it's non-blocking, you do the same loop, i.e. waiting for data arrival, blocking other tasks in your thread pool Maybe I misunderstood your code? UPD: fuck, i realised you wrote "but they block anyways", sorry :) But the question is why did you use non-blocking sockets at all, then?
@grenadier4702
@grenadier4702 14 күн бұрын
@@seanbix5366 oh gosh, freaking youtube deleting comments I checked out your code.Why did you use non-blocking sockets in the first place? Because I see even if errno is EWOULDBLOCK, you still iterate over and over waiting for data to arrive or send
@bladekiller2766
@bladekiller2766 15 күн бұрын
Isn't this simple HTTP server, that parses the requests and returns some response? Most of the backend frameworks already have this functionality implemented.
@seanbix5366
@seanbix5366 15 күн бұрын
@@bladekiller2766 Oh for sure. Dead simple, its in the title. If you want to actually be productive, you can always grab a library/framework for whatever. But now I don't have the third party dependencies, and I learned the protocol inside and out! From my experience- there's always an underestimated leap from thinking you understand a technology, to actually being able to implement it which can be fun to discover. Plus this is targeted more towards IT people, who often overestimate a lot of complexity in the tech they're using.
@bladekiller2766
@bladekiller2766 15 күн бұрын
@@seanbix5366 Couldn't agree more. All the tech stacks and networking complexity looks extremely complex, but when you try to implement it from scratch by yourself you will suddenly realize that it's doable and it will give you insights on why some things are the way they are. Props for doing it in C :)
@darkshoxx
@darkshoxx 14 күн бұрын
F*ck Powerpoint, we're using GIMP 😆! Excellent content
@minma02262
@minma02262 15 күн бұрын
Try http2 and http3. Very nice content 👍👍👍
@MadMatty72
@MadMatty72 3 күн бұрын
La-mans talk, live it
@Mikee512
@Mikee512 13 күн бұрын
Easy in C* *Except for dynamically sized strings. :P
@KangJangkrik
@KangJangkrik 10 күн бұрын
Now try SSL implementation and let's see if u can handle it
@seanbix5366
@seanbix5366 10 күн бұрын
Hah! Nice try, Sense Of Child-like Wonder! Unfortunately, I want to finish the project and get it working. SSL/TLS is a whole new can if worms for another time...
@ArtieOddity
@ArtieOddity 13 күн бұрын
Please Do Not Throw Sausage Pizza Away
@singhyuvraj122
@singhyuvraj122 15 күн бұрын
Great Video, Please more tutorials on Live coding of Email Server, HTTP and TCP /IP in C from scratch
@seanbix5366
@seanbix5366 15 күн бұрын
@@singhyuvraj122 I won't be doing any TCP/IP implementation until I end up working more in embedded and need to make one. An email server sounds rad though!
@MarkHall-cf6ji
@MarkHall-cf6ji 14 күн бұрын
​@@seanbix5366i think sockets allow you to send raw link-layer packets (ethernet frames) so you can probably implement TCP/IP from userspace
@xorxpert
@xorxpert 11 күн бұрын
TCP/HTTP is easy, then I went too hell with WebSocket but I pulled through lol, but I hate those frames.
@seanbix5366
@seanbix5366 11 күн бұрын
@@xorxpert Nice! I have a websocket deepdive on this channel too- the variable length length encoding and payload masking were wicked, but worth it in the end!
@xorxpert
@xorxpert 11 күн бұрын
@@seanbix5366 It was mostly challenging for me at the time. I usually like to learn how things work for experience but mostly avoiding third party or standard libraries. Whilst working on a multiplayer game, I built my own websocket server & client in the process along with a protocol library, for handling sending packets efficiently properly writing/reading and parsing data (binary), while converting between respectable objects. latency was very important, all unmanaged code. Performance, speed, and efficiency was the focus. Per protocol standard for large payloads, you have to deal with splitting the data into frames, and you know TCP, you got to handle waiting and acknowledging packets - multi (safe) threaded 😅 Took me about a mouth until i was entirely finished it, though was fun and worth learning!
@seanbix5366
@seanbix5366 11 күн бұрын
@@xorxpert So far none of my websocket payloads are larger than a few dozen bytes... But I was under the impression that I could simply cram an arbitrary amount of data after a websocket header and TCP would eat it? I don't remember, need to look at the code! I fetch all the BIG data with http from JS anyways.... Good work! I couldn't even find a simple websocket library anyways.
@michaelrenper796
@michaelrenper796 13 күн бұрын
I wrote HTTP from scratch in 1997 in Java. I was even easier.
@magibai
@magibai 14 күн бұрын
You Sir, deserve a subscribe
@kaushikkundu
@kaushikkundu 12 күн бұрын
Cfbr
@bonbonpony
@bonbonpony 12 күн бұрын
Dude! Ever heard of scope? As for someone who claims he wrote this code himself, you talk surprisingly few about the code, and surprisingly lot about unrelated deeper layers of protocols that you don't even attempt to implement yourself, and which are therefore totally outside of the scope.
@seanbix5366
@seanbix5366 12 күн бұрын
Fair. I suspected the overlap between between people who don't know HTTP and how the TCP/IP stack works was near 1:1, and targeted that audience. The implementation itself is not impressive (it's in the title) but it seems to have served it's purpose in giving lots of people a deeper intuition for the entire system (and powering my webserver)! I'm sure we can agree that conventional explanations (like wrapping a parcel) fall short.
@atomictraveller
@atomictraveller 14 күн бұрын
holmes, i'm asking you now, to stop doing anything from scratch. don't you know?
@ReligionAndMaterialismDebunked
@ReligionAndMaterialismDebunked 16 күн бұрын
First. Hehe. Shalom. Yeah, my nose is congested, too. I barely get sick as a vegan that exercises often, meditates, hydrates enough (unlike 75% of Americans and so forth), sleeps enough, good amounts of nutrients, breath work, fasting, etc.
@seanbix5366
@seanbix5366 16 күн бұрын
I'm sorry to hear that
@owenbrown9694
@owenbrown9694 15 күн бұрын
I have a soup recipe that'll fix you right up if you wanna hear it!
@stefanalecu9532
@stefanalecu9532 12 күн бұрын
You forgot this isn't Reddit
@swojnowski453
@swojnowski453 14 күн бұрын
It does not matter what you build, but what gets adopted ... Today you can build almost everything but who cares if nobody touches or builds on top of it.
@seanbix5366
@seanbix5366 14 күн бұрын
@@swojnowski453 I just want a cool video game for my friends and I, and to learn these technologies along the way. I'm building on top of it, I care, and its pretty chill!
@owenbrown9694
@owenbrown9694 15 күн бұрын
You cover nothing I wanted to know. Your grasp on the subject matter is below that of a hobbyist. This is harmful to the community, basically misinformation. Could you maybe sound less enthusiastic??
@seanbix5366
@seanbix5366 15 күн бұрын
Well, what would you like to know my guy?
@owenbrown9694
@owenbrown9694 15 күн бұрын
@@seanbix5366 When I made chicken pot pie, the filling was fine but the puff pastry on top didn't puff up though it did cook through. How can I remedy this? The pastry was the store-bought frozen variety. The temperature was 375 °C and I used and egg wash for the glaze.
@seanbix5366
@seanbix5366 15 күн бұрын
@@owenbrown9694 1. Thawing - Avoid an IP Collision Proper Thawing: Make sure your puff pastry isn't experiencing an IP (Instantly Pulled) collision by giving it time to thaw in the refrigerator, ensuring no network (temperature) congestion. 2. Temperature - Keep Your Layer 4 Connections Strong Correct Heat: Your oven needs to be set to 375 °F (190 °C). Think of it as keeping your TCP (Thermally Controlled Puff) connections strong. Too hot or too cold and you'll have trouble establishing that reliable connection for puffing! 3. Baking Setup - Packet Delivery Preheated Dish: Preheat your baking dish to prevent any packet loss, ensuring a more reliable delivery of puffiness. And remember, the filling should be hot, so the top layer gets a good handshake with the crust. 4. Egg Wash - Smooth Communication Application: Apply your egg wash gently, just like a smooth handshake protocol, to establish a golden connection without network (pastry) congestion. 5. Pastry Handling - Avoid Fragmentation Thickness: Roll out the puff pastry to about 1/4 inch, keeping it uniform to avoid data fragmentation in the layers, ensuring all packets (layers) arrive intact and puffed. 6. Pastry Resting - Time for ARP Resolution Cooling: Let your pastry rest for a bit in the fridge after rolling it out, allowing the Address Resolution Protocol (puff pastry layers) to map the correct layer addresses (butter) before baking. 7. Avoid Overhandling - Prevent DDoS (Dough Denial of Service) Minimal Handling: Don’t overhandle the dough or you’ll experience a DDoS attack on your puff pastry’s ability to rise! 8. Ventilation - Manage Network Traffic Steam Release: Make small slits in the pastry to manage network traffic (steam), ensuring no data packets (steam) get lost, causing network (pastry) puff loss. 9. Cover the Edges - Implement Firewall Rules Edge Protection: If the edges are browning too fast, cover them with foil as a firewall rule, letting the rest of the network (pastry) puff up securely without packet loss (burning). Troubleshooting Tips - Ping Your Pastry Temperature Checks: Make sure the oven temperature is accurate, much like pinging to check network latency. Proper Layering: Ensure the pastry's layers aren’t merging like a VLAN (Virtual Layers Absent Network). Steam Release: Remember, too much trapped steam can cause a denial of service on your puff pastry’s puffing ability! Summary Thaw properly: In the refrigerator, avoiding an IP collision. Correct temperature: 375-400 °F (190-200 °C) for solid TCP connections. Preheated dish: Ensures no packet loss. Gentle egg wash: For smooth handshake protocol. Minimal handling: Prevents DDoS on dough. Steam vents: Manage network traffic effectively. Edge protection: Implement firewall rules with foil. Let these tips serve as your protocol stack for perfect puff pastry puffing!
@owenbrown9694
@owenbrown9694 15 күн бұрын
@@seanbix5366 Thanks but could you give the instructions for a 300w microwave oven? Its all I got.
@seanbix5366
@seanbix5366 15 күн бұрын
@@owenbrown9694 Ah, you got me. The only thing I'll never open source.
@timemanager3239
@timemanager3239 13 күн бұрын
Goat 🦾🦾
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 329 М.
The End Of Jr Engineers
30:58
ThePrimeTime
Рет қаралды 369 М.
- А что в креме? - Это кАкАооо! #КондитерДети
00:24
Телеканал ПЯТНИЦА
Рет қаралды 7 МЛН
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 42 МЛН
How Hackers Bypass Kernel Anti Cheat
19:38
Ryscu
Рет қаралды 535 М.
Scientific Concepts You're Taught in School Which are Actually Wrong
14:36
Paraxial.io in 1 minute
0:57
Paraxial
Рет қаралды 3,5 М.
Writing My Own Database From Scratch
42:00
Tony Saro
Рет қаралды 184 М.
researchers find an unfixable bug in EVERY ARM cpu
9:48
Low Level Learning
Рет қаралды 423 М.
It’s time to move on from Agile Software Development (It's not working)
11:07
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 831 М.
God-Tier Developer Roadmap
16:42
Fireship
Рет қаралды 7 МЛН
The World Depends on 60-Year-Old Code No One Knows Anymore
9:30
Coding with Dee
Рет қаралды 613 М.
Why Didn't He Get the Job? Let's Find Out! // Code Review
27:25
The Cherno
Рет қаралды 70 М.
АЙФОН 20 С ФУНКЦИЕЙ ВИДЕНИЯ ОГНЯ
0:59
КиноХост
Рет қаралды 1,1 МЛН
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 4,1 МЛН
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 2,1 МЛН
Battery  low 🔋 🪫
0:10
dednahype
Рет қаралды 12 МЛН
😱Хакер взломал зашифрованный ноутбук.
0:54
Последний Оплот Безопасности
Рет қаралды 955 М.
Как распознать поддельный iPhone
0:44
PEREKUPILO
Рет қаралды 2 МЛН
Todos os modelos de smartphone
0:20
Spider Slack
Рет қаралды 58 МЛН