Turns out in Nebula3 it's just a couple of lines (I was actually surprised myself a little bit, even though I wrote the stuff), the TcpServer class already handles all the connection stuff, throw in a couple of stream readers and writers to decode and encode HTTP requests and responses and you have a simple HTTP server written in a couple of hours.
Here's roughly how it works:
- create and open a TcpServer object
- once per frame (or less frequently) poll the TcpServer for an array of TcpClientConnections (these are all the outstanding requests from web browsers)
- for each TcpClientConnection:
- attach a HttpRequestReader to the receive stream
- attach a HttpResponseWriter to the send stream
- decide what to send back based on the request, and fill the response with the result
- call TcpClientConnection::Send()
Here's the first message served from a Nebula3 application into a web browser:
What's missing now is some sort of HtmlWriter to write out simple HTML pages with the actual content, and a HttpImageWriter to send images to the web browser (to provide a gallery of all currently existing Texture objects).
Fun stuff.