https://learnbchs.org/ ?
Ask HN: Resources for Building a Webserver in C?
11–20 of 67 posts
Re: Ask HN: Resources for Building a Webserver in C?
#12Re: Ask HN: Resources for Building a Webserver in C?
#13Re: Ask HN: Resources for Building a Webserver in C?
#14Earlier quoted context omitted.
Being largely unfamiliar with C, I would prefer conceptual resources over source code. The why is more important than the how. Hopefully that makes sense?
conceptually things are pretty limited - this is really simple if you are just playing around, and are just doing http 1 o bind a socket o manage incoming connections o parse http headers o 'routing' - demultiplex handlers based on URL o encode response unless its a little embedded thing one usually uses some kind of select/epoll machinery to multiplex the work on each channel. I guess thread-per-request is another m…
I'm specifically interested in compressing my analytics stack. I'm currently interacting with HTTP Messages at a higher level. The problem, as I see it, is the webserver is already doing this work but without useful output. I'd like to implement my analytics paradigm natively at the webserver level.
Re: Ask HN: Resources for Building a Webserver in C?
#15Hands-On Network Programming with C by Lewis Van Winkle is a really good intro book for network programming with C.
Re: Ask HN: Resources for Building a Webserver in C?
#16Unix Network Programming by W. Richard Stevens and parts of The Linux Programming Interface by Michael Kerrisk
Re: Ask HN: Resources for Building a Webserver in C?
#17Beej's guide to network programming: https://beej.us/guide/bgnet/
Re: Ask HN: Resources for Building a Webserver in C?
#18Edit: I’ve heard that the first edition of TCP/IP illustrated has considerably more readable prose, so if you’re not doing IPv6 maybe get it instead. Apparently the 2nd edition with Fall is more of a rewrite with a considerable number if technical errors so I can’t recommend it having not read it.
Re: Ask HN: Resources for Building a Webserver in C?
#19If you wish, use the source. (Almost?) all early webservers were written in C.
Being largely unfamiliar with C, I would prefer conceptual resources over source code. The why is more important than the how. Hopefully that makes sense?
Re: Ask HN: Resources for Building a Webserver in C?
#20I reused the final version for a different university exercise instead of bothering with Tomcat as I was required, and back in 2015, dumped the end result here: https://github.com/AgentD/websrv where I kept adding to it for a while for fun.
The HTTP 1.x protocol itself is pretty dead simple (if you ignore chunked requests/responses and such) and the more interesting part was actually the socket code.
Back in school, our teacher had us write a simple forking server and consult the corresponding man pages (man 2 socket, man 7 socket, man 7 tcp). It was an acceptable minimal solution to not even look at the client request, respond with a static string containing a dummy response header and HTML page, which absolutely works. Bonus points for parsing the request path and sending a file back, more extra points if the path was a directory and your server sends back an "index.html" file, further points if it instead generates an HTML directory listing on the fly.
When I visited our former teacher a couple years ago, he had modified the exercise somewhat. He brought a Beagle Bone Black with him to class, with a bunch of I2C sensors attached to it, and the extended exercises now revolve around reporting temperature/humidity/... to the browser.
So, for "resource" I recommend the HTTP example on Wikipedia, as well as "Beej's guide to network programming" (as have others), as well as the man pages for quick reference.