Live data from Hacker News

Ask HN: Resources for Building a Webserver in C?

news.ycombinator.com

1–10 of 67 posts

Ask HN: Resources for Building a Webserver in C?

#1
I'm starting to work with C and would like to build a webserver. I've found a few interesting writeups but would love to hear from the community.

What's your favorite book/post/lecture/whatever? I'd also be interested in opinionated writeups/positions.

Re: Ask HN: Resources for Building a Webserver in C?

#3

If 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?

#6

If 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?

One of my favorite things to read is RFC 1945

Re: Ask HN: Resources for Building a Webserver in C?

#8

If 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?

Unfortunately, having done the same, there are a lot of lessons learned in existing source code that you won’t find elsewhere.

Re: Ask HN: Resources for Building a Webserver in C?

#10

If 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?

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 model that works at moderate connection counts.

it helps to have some decent way of representing the header to send to the handler, C doesn't really have a great story here

I think the only funky thing is dealing with all the various body modes. so you will need to make some kind of protocol to deal with handlers and incremental updates if that's a thing for your use case.

I would just do the normal thing, read the rfc and spit out a couple hundred lines that talks to your browser...and then decide where if anywhere you need to go from there

Post reply on HN