1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 17:35:10 +00:00

WebServer: Implement a very basic HTTP server :^)

This server listens on port 8000 and serves HTML files from /www.
It's very simple and quite naive, but I think we can start here and
build our way to something pretty neat.

Work towards #792.
This commit is contained in:
Andreas Kling 2020-02-09 12:04:58 +01:00
parent 271bc4b2f2
commit 6c752c15a2
8 changed files with 198 additions and 1 deletions

View file

@ -0,0 +1,23 @@
#include "Client.h"
#include <LibCore/EventLoop.h>
#include <LibCore/TCPServer.h>
int main(int argc, char** argv)
{
(void)argc;
(void)argv;
Core::EventLoop loop;
auto server = Core::TCPServer::construct();
server->on_ready_to_accept = [&] {
auto client_socket = server->accept();
ASSERT(client_socket);
auto client = WebServer::Client::construct(client_socket.release_nonnull(), server);
client->start();
};
server->listen({}, 8000);
return loop.exec();
}