TCP Server
Accept connections.
Building a TCP Server
A TCP server waits for clients and accepts their connections. The lifecycle is: create a socket, bind it to a port, listen, then accept connections in a loop.
Step 1: Create the Socket
Create a stream socket for IPv4 TCP. A negative result means failure.
#include <sys/socket.h>
#include <stdio.h>
int make_server_socket(void) {
int fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0) { perror("socket"); }
return fd;
}