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?
num_read = read(STDIN_FILENO, buf, BUF_SIZE);
if (num_read == 0) {
    break;
}
buf[num_read] = '\0';

if (write(sock_fd, buf, num_read) != num_read) {
    perror("client: write");
    close(sock_fd);
    exit(1);
}

num_read = read(sock_fd, buf, sizeof(buf) - 1);
if (num_read == 0) {
    break;
}
buf[num_read] = '\0';
printf("[Server] %s", buf);
}