30 lines
607 B
Plaintext
30 lines
607 B
Plaintext
|
|
|
||
|
|
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;
|
||
|
|
}
|