Тёмный

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

Sean Bix
Подписаться 3,5 тыс.
Просмотров 36 тыс.
50% 1

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!

Наука

Опубликовано:

 

11 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 67   
@lukeh990
@lukeh990 3 дня назад
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”
@Q_20
@Q_20 4 дня назад
I read that as C written in HTTP, and was hoping for next level black magic shit.
@seanbix5366
@seanbix5366 4 дня назад
If anybody is determined to bless the world with this, I'll help where I can!
@vpd825
@vpd825 Час назад
Same here 😂 This is still cool.
@shreeyashpandey3530
@shreeyashpandey3530 4 дня назад
That's a very creative way to use gimp as a presentation tool! hella based video!
@shinej11
@shinej11 3 дня назад
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 3 дня назад
@@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 4 дня назад
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.
@impaglg
@impaglg 9 часов назад
Thank you for this video Sean! it really was eye opening.
@whonehuljain
@whonehuljain 4 дня назад
Great content, also amazing explaination!
@s1ckret
@s1ckret 5 дней назад
Great work, man!
@iSam36O
@iSam36O 3 дня назад
moonfly gang 🔥 great video btw, keep them coming!
@prashlovessamosa
@prashlovessamosa 3 дня назад
Wow great learnt a lot keep uploading good stuff.
@SamirPatnaik
@SamirPatnaik 5 дней назад
S+ tier content
@JeremyAndersonBoise
@JeremyAndersonBoise 3 дня назад
This is a great practice project for programmers. Very cool moves.
@SalirDeMatrix
@SalirDeMatrix 3 дня назад
You are a good developer. 👍
@DailyFrankPeter
@DailyFrankPeter 3 дня назад
In the worlds of Linus Torvalds - let's write it from scratch; how hard can it be!
@DanielPopsuevich
@DanielPopsuevich 4 дня назад
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.
@AndrewNijmeh
@AndrewNijmeh 3 дня назад
this is how real men program 🙏🏼
@bennguyen1313
@bennguyen1313 4 дня назад
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 4 дня назад
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!
@user-lv5vj1vo9t
@user-lv5vj1vo9t 3 дня назад
How different is this from the binary HTTP protocol? And can you leverage your code into that easily?
@seanbix5366
@seanbix5366 3 дня назад
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!
@justcurious1940
@justcurious1940 5 дней назад
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 5 дней назад
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 4 дня назад
​@@seanbix5366 Thank u for clarifying this. Good luck with what ever u are doing today or u are planing to do tomorrow 🙃.
@fabienWendpanga
@fabienWendpanga 6 дней назад
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 5 дней назад
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!
@grenadier4702
@grenadier4702 4 дня назад
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 4 дня назад
@@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 4 дня назад
​@@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 3 дня назад
@@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
@andregeraldo6556
@andregeraldo6556 3 дня назад
just got smarter watching this lol, good video
@KangJangkrik
@KangJangkrik 2 часа назад
Now try SSL implementation and let's see if u can handle it
@Mikee512
@Mikee512 3 дня назад
Easy in C* *Except for dynamically sized strings. :P
@darkshoxx
@darkshoxx 4 дня назад
F*ck Powerpoint, we're using GIMP 😆! Excellent content
@minma02262
@minma02262 4 дня назад
Try http2 and http3. Very nice content 👍👍👍
@bladekiller2766
@bladekiller2766 4 дня назад
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 4 дня назад
@@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 4 дня назад
@@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 :)
@ArtieOddity
@ArtieOddity 2 дня назад
Please Do Not Throw Sausage Pizza Away
@michaelrenper796
@michaelrenper796 2 дня назад
I wrote HTTP from scratch in 1997 in Java. I was even easier.
@singhyuvraj122
@singhyuvraj122 5 дней назад
Great Video, Please more tutorials on Live coding of Email Server, HTTP and TCP /IP in C from scratch
@seanbix5366
@seanbix5366 4 дня назад
@@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 3 дня назад
​@@seanbix5366i think sockets allow you to send raw link-layer packets (ethernet frames) so you can probably implement TCP/IP from userspace
@xorxpert
@xorxpert 22 часа назад
TCP/HTTP is easy, then I went too hell with WebSocket but I pulled through lol, but I hate those frames.
@seanbix5366
@seanbix5366 22 часа назад
@@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 22 часа назад
@@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 22 часа назад
@@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.
@bonbonpony
@bonbonpony День назад
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 День назад
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.
@magibai
@magibai 3 дня назад
You Sir, deserve a subscribe
@kaushikkundu
@kaushikkundu День назад
Cfbr
@atomictraveller
@atomictraveller 3 дня назад
holmes, i'm asking you now, to stop doing anything from scratch. don't you know?
@ReligionAndMaterialismDebunked
@ReligionAndMaterialismDebunked 6 дней назад
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 5 дней назад
I'm sorry to hear that
@owenbrown9694
@owenbrown9694 4 дня назад
I have a soup recipe that'll fix you right up if you wanna hear it!
@stefanalecu9532
@stefanalecu9532 День назад
You forgot this isn't Reddit
@swojnowski453
@swojnowski453 3 дня назад
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 3 дня назад
@@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 4 дня назад
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 4 дня назад
Well, what would you like to know my guy?
@owenbrown9694
@owenbrown9694 4 дня назад
@@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 4 дня назад
@@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 4 дня назад
@@seanbix5366 Thanks but could you give the instructions for a 300w microwave oven? Its all I got.
@seanbix5366
@seanbix5366 4 дня назад
@@owenbrown9694 Ah, you got me. The only thing I'll never open source.
@timemanager3239
@timemanager3239 3 дня назад
Goat 🦾🦾
Далее
Coding a Web Server in 25 Lines - Computerphile
17:49
Просмотров 327 тыс.
Хотите поиграть в такую?😄
00:16
Просмотров 219 тыс.
I Wrote Websockets "From Scratch"
14:21
Просмотров 17 тыс.
Quest To Find The Largest Number
11:43
Просмотров 111 тыс.
The Right Way To Build REST APIs
10:07
Просмотров 43 тыс.
The End Of Jr Engineers
30:58
Просмотров 304 тыс.
100+ Linux Things you Need to Know
12:23
Просмотров 712 тыс.
Everything Starts with a Note-taking System
21:23
Просмотров 112 тыс.
Making Minimalist Web Server in C on Linux
10:23
Просмотров 232 тыс.
Why Does Scrum Make Programmers HATE Coding?
16:14
Просмотров 503 тыс.
OZON РАЗБИЛИ 3 КОМПЬЮТЕРА
0:57
Просмотров 1,5 млн