Connect to the server, ask for and store their name. Then allow them to enter commands.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>         /* gethostname */
#include <sys/socket.h>
#include "friends.h"

#ifndef PORT
  #define PORT 58364
#endif

#define BUFSIZE 30

/*
 * Initialize a server address associated with the given port.
 */
struct sockaddr_in *init_server_addr(int port) {
    struct sockaddr_in *addr = malloc(sizeof(struct sockaddr_in));
    addr->sin_family = AF_INET;
    addr->sin_port = htons(port);
    memset(&(addr->sin_zero), 0, 8);
    addr->sin_addr.s_addr = INADDR_ANY;

    return addr;
}

int set_up_server_socket(struct sockaddr_in *self, int num_queue) {
    int soc = socket(AF_INET, SOCK_STREAM, 0);
    if (soc < 0) {
        perror("socket");
        exit(1);
    }

    int on = 1;
    int status = setsockopt(soc, SOL_SOCKET, SO_REUSEADDR,
                            (const char *) &on, sizeof(on));
    if (status < 0) {
        perror("setsockopt");
        exit(1);
    }

    if (bind(soc, (struct sockaddr *)self, sizeof(*self)) < 0) {
        perror("bind");
        exit(1);
    }

    // Set up a queue in the kernel to hold pending connections.
    if (listen(soc, num_queue) < 0) {
        perror("listen");
        exit(1);
    }

    return soc;
}

int accept_connection(int listenfd) {
    struct sockaddr_in peer;
    unsigned int peer_len = sizeof(peer);
    peer.sin_family = AF_INET;

    int client_socket = accept(listenfd, (struct sockaddr *)&peer, &peer_len);
    if (client_socket < 0) {
        perror("accept");
        return -1;
    } 
    char message[BUFSIZE];
    sprintf(message, "What is your name?\r\n");
    write(client_socket, message, strlen(message));
    
    return client_socket;
    
}

int main() {

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

    printf("What is your name?\n");

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

        close(fd);
        printf("The connection is now closed ...\n");
    }
    free(self);
    close(listenfd);
    return 0;
}