From d8036aa78139c7890d8adde6ee937929623dbffb Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 19 Nov 2020 18:53:48 +0100 Subject: Reimplemented basic webserver --- apps/server.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 apps/server.c (limited to 'apps/server.c') diff --git a/apps/server.c b/apps/server.c new file mode 100644 index 0000000..646e876 --- /dev/null +++ b/apps/server.c @@ -0,0 +1,28 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#include +#include +#include +#include + +#define PORT 8000 +#define RESP "HTTP/1.1 200\r\nContent-Length: 14\r\nConnection: close\r\n\r\n

Hallo

" + +int main() +{ + printf("Server running on port %d\n", PORT); + + while (1) { + struct socket *socket = net_open(S_TCP); + assert(socket); + socket->src_port = PORT; + socket->state = S_CONNECTED; + char buf[4096] = { 0 }; + net_receive(socket, buf, 4096); + printf("%s\n", buf); + net_send(socket, strdup(RESP), strlen(RESP)); + /* net_close(socket); // TODO: Fix */ + } + + return 0; +} -- cgit v1.2.3