first
This commit is contained in:
64
source/main.c
Normal file
64
source/main.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* #############################################################################
|
||||
* # DesingedWorlds
|
||||
*
|
||||
*
|
||||
* AUTHER: PreacherDHM
|
||||
* DATE: MM/DD/YY
|
||||
* #############################################################################
|
||||
*/
|
||||
|
||||
#include "http.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
int main() {
|
||||
int sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sockaddr_in addr;
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(9090);
|
||||
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
|
||||
|
||||
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||
perror("bind");
|
||||
return -1;
|
||||
}
|
||||
|
||||
listen(sock, 3);
|
||||
printf("Server started. Listening on port 9090.\n");
|
||||
|
||||
while (1) {
|
||||
int client_sock = accept(sock, NULL, NULL);
|
||||
if (client_sock < 0) {
|
||||
perror("accept");
|
||||
continue;
|
||||
}
|
||||
|
||||
char* response = (char*)malloc(512); // Assuming a maximum length of 512 bytes
|
||||
|
||||
HttpResponseHeader* header = createHttpResponse(200, HTTP_CONTENT_TYPE_HTML,
|
||||
"<h1>This is a test to see what happends</h1>", response, 512);
|
||||
|
||||
|
||||
printf("%s\n", response);
|
||||
|
||||
|
||||
printf("Sent 'Hello, World!' to the client.\n");
|
||||
|
||||
send(client_sock, response, strlen(response)+1, 0);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user