Last active
September 16, 2016 13:53
-
-
Save Bueddl/b8aa85e44f90aca7625695d5310694b6 to your computer and use it in GitHub Desktop.
my shitty server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <arpa/inet.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
int sock = socket(AF_INET, SOCK_STREAM, 0); | |
struct sockaddr_in addr; | |
memset(&addr, 0, sizeof(addr)); | |
addr.sin_family = AF_INET; | |
addr.sin_port = htons(7331); | |
inet_aton("127.0.0.1", &addr.sin_addr.s_addr); | |
bind(sock, (struct sockaddr*)addr, sizeof(addr)); | |
listen(sock, 10); // <-- backlog | |
int client_sock; | |
struct sockaddr_in client_addr; | |
socklen_t addrlen = sizeof(client_addr); | |
// get next client connection (wait or pull from backlog) | |
while (client_sock = accept(sock, (struct sockaddr*)&client_addr, &addrlen)) | |
{ | |
// extremly slow processing... | |
close(client_sockt); | |
} | |
// why ever we would end up here | |
close(sock); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment