how to Monitor stdin and the socket using select to avoid blocking on either one.
#ifndef PORT
#define PORT 30000
#endif
#define MAX_BACKLOG 5
#define MAX_CONNECTIONS 12
#define BUF_SIZE 128

while (1) {
    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);
}