int main() {
    setbuf(stdout, NULL);

    struct sockaddr_in *self = init_server_addr(PORT);
    int listenfd = set_up_server_socket(self, 5);

    while (1) {
        int fd = accept_connection(listenfd);
        if (fd < 0) {
            continue;
        }

        char buf[BUFSIZE] = {'\0'};
        int inbuf = 0;
        int room = sizeof(buf);
        char *after = buf;
        int nbytes;
        while ((nbytes = read(fd, after, room)) > 0) {
            inbuf += nbytes;

            int where;

            while ((where = find_network_newline(buf, inbuf)) > 0) {
                buf[where - 2] = '\0';
                printf("Next message: %s\n", buf);

                inbuf = inbuf - where;

                for (int i = 0; i < where; i++) {
                    buf[i] = '\0';
                }

                memmove(buf, buf + where, inbuf);

                for (int i = where; i < BUFSIZE; i++) {
                    buf[i] = '\0';
                }
            }
            after = buf + inbuf;
            room = BUFSIZE - inbuf;
        }
        close(fd);
        printf("The connection is now closed ...\n");
    }

    free(self);
    close(listenfd);
    return 0;
}