 I am attempting to set up a connection between a client and a server, where the client reads from stdin, then writes to the server, then reads from the server and prints output, and the server reads from the client and then writes it back to them, but there is a one-write delay. This is my client code. what is the issue?
int read_from(int client_index, struct sockname *users) {
    int fd = users[client_index].sock_fd;
    char buf[BUF_SIZE + 1];

    int num_read = read(fd, &buf, BUF_SIZE);
    buf[num_read] = '\0';
    if (num_read == 0 || write(fd, buf, strlen(buf)) != strlen(buf)) {
        users[client_index].sock_fd = -1;
        return fd;
    }

    if (users[client_index].username == NULL) {
        // username hasn't been set yet
        users[client_index].username = malloc(num_read);
        if (users[client_index].username == NULL) {
            perror("malloc");
            exit(1);
        }
        strcpy(users[client_index].username, buf);
    }

    return 0;
}