chore: restructure project into src/tests/examples directories with modular build system
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
|
||||
int main() {
|
||||
int server_fd;
|
||||
int client_fd;
|
||||
char buffer[1024];
|
||||
char *response;
|
||||
int bytes;
|
||||
int response_len;
|
||||
int count;
|
||||
|
||||
printf("Creating socket\n");
|
||||
server_fd = socket(AF_INET(), SOCK_STREAM(), 0);
|
||||
|
||||
printf("Binding\n");
|
||||
bind(server_fd, 8080);
|
||||
|
||||
printf("Listening\n");
|
||||
listen(server_fd, 10);
|
||||
|
||||
printf("Server listening on port 8080\n");
|
||||
|
||||
count = 0;
|
||||
while (count < 100) {
|
||||
printf("Waiting for connection\n");
|
||||
client_fd = accept(server_fd, 0, 0);
|
||||
printf("Client connected\n");
|
||||
|
||||
bytes = recv(client_fd, buffer, 1024, 0);
|
||||
printf("Received %d bytes\n", bytes);
|
||||
|
||||
response = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n<html><body><h1>Hello from Mini C HTTP Server!</h1><p>This server runs on a custom C interpreter.</p></body></html>";
|
||||
response_len = strlen(response);
|
||||
send(client_fd, response, response_len, 0);
|
||||
|
||||
close(client_fd);
|
||||
printf("Connection closed\n");
|
||||
count = count + 1;
|
||||
}
|
||||
|
||||
close(server_fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
int main() {
|
||||
int server_fd;
|
||||
int client_fd;
|
||||
char buffer[4096];
|
||||
char *response;
|
||||
int bytes_received;
|
||||
int response_len;
|
||||
int count;
|
||||
|
||||
server_fd = socket(AF_INET(), SOCK_STREAM(), 0);
|
||||
bind(server_fd, 8080);
|
||||
listen(server_fd, 10);
|
||||
|
||||
printf("Server listening on port 8080\n");
|
||||
|
||||
count = 1;
|
||||
while (count > 0) {
|
||||
printf("Waiting for connection %d\n", count);
|
||||
client_fd = accept(server_fd, 0, 0);
|
||||
printf("Client connected\n");
|
||||
|
||||
bytes_received = recv(client_fd, buffer, 4096, 0);
|
||||
printf("Received %d bytes\n", bytes_received);
|
||||
|
||||
response = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n<html><body><h1>Hello from Mini C!</h1><p>Request number: ";
|
||||
response_len = strlen(response);
|
||||
send(client_fd, response, response_len, 0);
|
||||
|
||||
close(client_fd);
|
||||
printf("Connection closed\n");
|
||||
count = count + 1;
|
||||
}
|
||||
|
||||
close(server_fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
int main() {
|
||||
int sockfd;
|
||||
int client_fd;
|
||||
char buffer[1024];
|
||||
int bytes;
|
||||
|
||||
printf("Creating socket\n");
|
||||
sockfd = socket(AF_INET(), SOCK_STREAM(), 0);
|
||||
|
||||
printf("Binding\n");
|
||||
bind(sockfd, 8080);
|
||||
|
||||
printf("Listening\n");
|
||||
listen(sockfd, 10);
|
||||
|
||||
printf("Waiting for connection\n");
|
||||
client_fd = accept(sockfd, 0, 0);
|
||||
printf("Client connected: %d\n", client_fd);
|
||||
|
||||
bytes = recv(client_fd, buffer, 100, 0);
|
||||
printf("Received %d bytes\n", bytes);
|
||||
|
||||
send(client_fd, "HTTP/1.1 200 OK\n\nHello!\n", 24, 0);
|
||||
|
||||
close(client_fd);
|
||||
close(sockfd);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user