Making Minimalist HTTPS Server in C on Linux

  Рет қаралды 21,464

Nir Lichtman

Nir Lichtman

Күн бұрын

Пікірлер: 69
@nirlichtman
@nirlichtman Жыл бұрын
- Notice that if you run the server quickly after running it before, bind might fail since the port may not be cleaned up yet, so I recommend running the server with ltrace/strace so you can actually see what is going on under the hood, my new video about the importance of error handling in c also talks about this specifically
@enesalbay9707
@enesalbay9707 7 ай бұрын
Add setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) before bind to overcome this problem.
@space9824
@space9824 Жыл бұрын
These videos are so insightful, especially the way you show the man pages where you can find all this information. I literally didn't even know C library functions had man pages until I starting watching your content.
@iamspeed1405
@iamspeed1405 Жыл бұрын
Geez I opened the video and BOOM! it was straight into the action no silly 1 minute long intro. Love it ❤!
@Dysl3xicDog
@Dysl3xicDog Жыл бұрын
The way you put the documentation digging into the videos is super helpful. The thing that's lost on me at this point is how you discover the functions you need to use before you hit the docs for each item.
@nirlichtman
@nirlichtman Жыл бұрын
Thanks for the feedback I will try talking more about the discovery as well on future videos, check out my man pages tips video for general tips about finding man pages.
@bromophenol2469
@bromophenol2469 Жыл бұрын
Nir, your distinct no nonsense style is very refreshing
@Maagiicc
@Maagiicc Жыл бұрын
Thanks for the longer video and more complicated program. Do you have any plans on doing anything non-minimalist?
@nirlichtman
@nirlichtman Жыл бұрын
Yes, I am planning on perhaps fully implementing one of the unix commands :)
@StefanWelebny
@StefanWelebny Жыл бұрын
Could you show how to handle concurrent requests and concurrent listeners?
@AlTiri-rd7ly
@AlTiri-rd7ly Жыл бұрын
​​@reapiu8316yeah I would love to see that, although I really loke these semi short videos.
@hermessantos181
@hermessantos181 Жыл бұрын
awesome!@reapiu8316
@spacewad8745
@spacewad8745 Жыл бұрын
Ah you've read my mind! I just started messing around with sockets and was about to try my hand at developing a simple http server.
@Kim-e4g4w
@Kim-e4g4w Жыл бұрын
Wow I guess Christmas came early this year. This opens up many possibilities with all kinds of web services. Only imagination is the limit! Thank you soo much!
@Temon0942
@Temon0942 Жыл бұрын
Hey bro your videos are amazing keep making them
@quezinmark8225
@quezinmark8225 Жыл бұрын
Making short videos are good but giving overview about what you're going to do would make it better I mean explaining flow!
@ItsCOMMANDer_
@ItsCOMMANDer_ Жыл бұрын
My wish has been heared, thx
@sashakuznechkin
@sashakuznechkin Жыл бұрын
Thanks for video! Happy new year!
@pavfrang
@pavfrang Жыл бұрын
WOW - that is original hack stuff. Love it. Carry on!
@pogchamper228
@pogchamper228 4 ай бұрын
How do you know, or where did you learned which functions to use? I also use man pages but always struggle to begin with.
@tan4296
@tan4296 Жыл бұрын
I really like your thumbnails
@Humble_Electronic_Musician
@Humble_Electronic_Musician Жыл бұрын
This is good stuff! Awesome!
@rogo7330
@rogo7330 Жыл бұрын
I believe it's better to use separate TLS reverse proxies that will do TLS stuff and then pass the connection to next program by just connecting to localhost port or unix socket. It makes programs much simplier and can become a problem only on high load servers, where you don't want too many calls to write and read from programs because it's more user-kernel context switching.
@nirlichtman
@nirlichtman Жыл бұрын
I agree about this point, for actual production it would be better to separate the HTTP server and the SSL server, or to just use nginx :)
@davidgillies620
@davidgillies620 Жыл бұрын
If you need to implement a production-grade HTTPS server in C++, Vinnie Falco's Beast library is the way to go.
@justcurious1940
@justcurious1940 7 ай бұрын
Great videos bro, Thanks.
@berserkeropo4085
@berserkeropo4085 13 күн бұрын
Would this also work on Windows? And if not, is it possible to make one for Windows?
@zifebort2308
@zifebort2308 5 күн бұрын
it is, i think he made a similar video about this for windows. So instead of using sys/socket.h (which is not available in windows) you will use winsock2.h (but you also need visual studio, or at least the visual studio command-line toolset, because in that vid he uses "cl"). Though the video is not about http (after I checked) you can still use that info to understand the concept at least 👍
@luadicrous
@luadicrous Жыл бұрын
I found out that if you hold F5 in the browser for a while it can make it 'crash'. It's not a real crash however, it's the SIGPIPE signal that is being fired and it happens when a pipe gets broken. You can capture this event with the 'signal' function if you are on Unix based systems, but no idea what the equivalent on Windows is. Once you've captured this signal, you can just ignore it and the server keeps running.
@Garfield_Minecraft
@Garfield_Minecraft 3 ай бұрын
Can I follow the tutorial on windows? and can you make a tutorial that the user can be host? kinda like a room system or group chat with this would be cool
@nirlichtman
@nirlichtman 3 ай бұрын
I haven't tested on Windows, but I assume that it would be a similar deal, I do have a video of making a simple http server with winsock, so that can be a starting point. About the second point, I have a video about making a simple HTTP chat system :)
@hulio3994
@hulio3994 6 ай бұрын
I love your workflow, I'd really love to program using man pages and simple text editors but I always feel stuck when programming without a proper IDE. How did you practice C programming when you started?
@nirlichtman
@nirlichtman 6 ай бұрын
Thanks! I started with IDEs (mostly Visual Studio) and then gradually moved over to Vim, first by using a Vim plugin on the IDE and then after feeling comfortable enough, I moved to Vim vanilla.
@samjiman
@samjiman Жыл бұрын
Nice videos. What is the window manager you are using on Windows?
@nirlichtman
@nirlichtman Жыл бұрын
I am using dwm-win32, more info about the setup in the welcome link in the channel description
@samjiman
@samjiman Жыл бұрын
@@nirlichtman Thanks, Nir.
@dkkogmaw1311
@dkkogmaw1311 8 ай бұрын
How can you link it static … im stuck at this point
@ttrss
@ttrss Жыл бұрын
aw your not writing a c implement of tls in 15 minutes
@mrlistenerr
@mrlistenerr 8 ай бұрын
Well, wouldn't it be better to send a corresponding HTTP error code (instead of 200 OK each time) when you return a "not found" error?
@erbenton07
@erbenton07 Жыл бұрын
Hi, what editor are you using? I'd like to try it out.
@nirlichtman
@nirlichtman Жыл бұрын
I am using Vim, many of my older videos are about it if you want more info
@DrDulos
@DrDulos 11 ай бұрын
Thanks, good work
@bob-007
@bob-007 Жыл бұрын
great stuff thanks, any chance of something similar but in Python?
@nirlichtman
@nirlichtman Жыл бұрын
Good idea, noted :)
@Alex_Yuschenko
@Alex_Yuschenko Ай бұрын
Groovy! ))
@kimlehtinen
@kimlehtinen Жыл бұрын
Interesting! Is this what NGINX does under the hood when configured as reverse proxy with SSL?
@nirlichtman
@nirlichtman Жыл бұрын
I haven't explored the NGINX source code yet, but I assume it works pretty similar, I am pretty sure it also uses OpenSSL :)
@soniablanche5672
@soniablanche5672 Жыл бұрын
I don't think it's as simple as that. NGINX could be running TLS with http version 2 and it is redirecting the http request to a local web server that is not using TLS and is using http version 1.
@ItsCOMMANDer_
@ItsCOMMANDer_ Жыл бұрын
Hey Nir, i used openssl commandline utility to generate key and cert. i changed "SSL_use_certificate_chain_file(ssl, "fullChain");" to "SSL_use_certificate_file(ssl, "key.pem", SSL_FILETYPE_PEM);" and ajusted file name.I compiled and ran it gave me an "The connection was reset The connection to the server was reset while the page was loading." error. can you help?
@nirlichtman
@nirlichtman Жыл бұрын
Is that the error you got from the web browser? Reason is probably because the certificate is self-signed, and the browser is rejecting the connection, if you want to try out the server you can use wget with the ignore cert option or try configurating the browser to accept the self-signed cert. If you want it to work out of the box you need to get a certificate signed by a certificate authority, on my setup in the video for example I used my certificate and private generated by let's encrypt which is a service that lets you easily get a certificate for your server
@ItsCOMMANDer_
@ItsCOMMANDer_ Жыл бұрын
​@@nirlichtman, update, i added an printf debug statement to nearly every function call wich prints its return value, and i found out that `bind()` returns an error (-1) when it doesnt work and success if it works (to download) could the reason be that in the code (because its not "production ready") an "un-bind" is missing?
@Acorn_Anomaly
@Acorn_Anomaly Жыл бұрын
@@ItsCOMMANDer_ There's no need to "unbind". The binding of the socket is released when the server socket is closed. If bind() is returning -1, then as you said, something is going wrong. When you get a failure, you should add code to print out the value of the errno special variable, to see what the error is. (See the bind(2) man page for more info.)
@honeymak
@honeymak 10 ай бұрын
i just wonder how you know the sequence of function calls beforehand
@nirlichtman
@nirlichtman 10 ай бұрын
On most cases the man pages/docs are sufficient to help me do the preliminary research, but specifically in the case of OpenSSL, which has quite poor docs in my opinion, I had to also do online research
@MarcoLeong
@MarcoLeong Жыл бұрын
What is that {0} terminator for?
@nirlichtman
@nirlichtman Жыл бұрын
That is standard C syntax to initialize all array members with 0, as long as you are not using an old/weird C compiler, it works nicely :) devdocs.io/c/language/array_initialization
@zedeleyici.1337
@zedeleyici.1337 4 ай бұрын
I liked that.
@rian0xFFF
@rian0xFFF Жыл бұрын
Do some basic OpenGL stuff or some UI
@nirlichtman
@nirlichtman Жыл бұрын
I am planning a future UI video about making a minimalist paint app for Windows. OpenGL is a good idea, noted :)
@rian0xFFF
@rian0xFFF Жыл бұрын
@@nirlichtman 😊
@leonss2356
@leonss2356 Жыл бұрын
noice
@yargonslavter
@yargonslavter Жыл бұрын
Narration: Great Content: Great Code Editor: C'mon man, use Visual Code
@nirlichtman
@nirlichtman Жыл бұрын
My favorite editor is Vim, in some of my older videos I explain why :)
@rajveer_2009
@rajveer_2009 10 ай бұрын
upgrade your vim
@rickdearman9992
@rickdearman9992 Жыл бұрын
It annoys me you use void for main. That is very C++ not C. 😂
@benhetland576
@benhetland576 Жыл бұрын
It is not very C++ either.
Adding Simple System Call in Linux Kernel
7:44
Nir Lichtman
Рет қаралды 19 М.
Making Minimalist Chat Server in C on Linux
14:28
Nir Lichtman
Рет қаралды 45 М.
We Attempted The Impossible 😱
00:54
Topper Guild
Рет қаралды 56 МЛН
Try this prank with your friends 😂 @karina-kola
00:18
Andrey Grechka
Рет қаралды 9 МЛН
Sigma Kid Mistake #funny #sigma
00:17
CRAZY GREAPA
Рет қаралды 30 МЛН
Making Minimalist HTTPS Client in C on Linux
9:12
Nir Lichtman
Рет қаралды 15 М.
i wrote my own memory allocator in C to prove a point
5:23
Low Level
Рет қаралды 413 М.
20 months developing a web server in C
10:59
Roy Salazar
Рет қаралды 9 М.
Coding a Web Server in 25 Lines - Computerphile
17:49
Computerphile
Рет қаралды 360 М.
I Wrote HTTP "From Scratch" (It Was Easy)
19:07
Sean Bix
Рет қаралды 90 М.
Making Simple Graphical Linux Distro from Scratch
17:19
Nir Lichtman
Рет қаралды 72 М.
Self-Hosted TRUST with your own Certificate Authority!
26:25
apalrd's adventures
Рет қаралды 39 М.
Making Minimalist Web Server in C on Windows
10:52
Nir Lichtman
Рет қаралды 11 М.
Making a Very Minimal Windows Executable in C
7:48
Nir Lichtman
Рет қаралды 95 М.
пранк🤣😂😂
0:51
Numdexx1
Рет қаралды 1,2 МЛН
SH - Anh trai & Em gái || Brother & Sister #shorts
0:58
Su Hao
Рет қаралды 48 МЛН
НЕ ДАМ ЕЁ В ОБИДУ😡 #shorts
0:24
Паша Осадчий
Рет қаралды 1,6 МЛН
🪄Вечная спичка #diy #выживание #поход
1:00
Короче, ВИ
Рет қаралды 2,8 МЛН