aboutsummaryrefslogtreecommitdiff
path: root/apps/server.c
blob: ceb5ed0d3574d813d9a1db57cdf8b8d2c3d6d3db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// MIT License, Copyright (c) 2020 Marvin Borner

#include <assert.h>
#include <net.h>
#include <print.h>
#include <str.h>

#define PORT 8000
#define RESP "HTTP/1.1 200\r\nContent-Length: 14\r\nConnection: close\r\n\r\n<h1>Hallo</h1>"

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);
		net_send(socket, strdup(RESP), strlen(RESP));
		net_close(socket);
	}

	return 0;
}