Socket client in C using threads I'm working on socket programming in C. I have no problem with usage the threads. This all works fine but I'm new in this area. I wrote this code in client.c but is there any misused code or something may cause problems in the future?
My client sends a message to the server and client can receive it. There are 2 major operations: recv and send.
CLIENT
#include&lt;stdio.h&gt;
#include&lt;sys/socket.h&gt;
#include&lt;arpa/inet.h&gt; // for inet_addr
#include &lt;string.h&gt;
#include &lt;zconf.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;pthread.h&gt;

void *sendMessage(void *sock_desc) {
    //Send some data
    while (1) {
        char message[2000];
        printf(&quot;%s&quot;,&quot;&gt; &quot;);
        scanf(&quot;%[^\n]%*c&quot;, message);
        fflush(stdin);

        if (send(*((int *) sock_desc), message, strlen(message) + 1, 0) &lt; 0) {
            puts(&quot;Send failed&quot;);
        }
    }
}

void *receiveMessage(void *sock_desc) {
    while (1) {
        char server_reply[2000];
        if (recv(*((int *) sock_desc), server_reply, 2000, 0) &lt; 0) {
            puts(&quot;recv failed&quot;);

        }
        //Receive a reply from the server
        printf(&quot;\033[32;1m %s \033[0m\n&quot;, server_reply);
    }
}

int main(int argc, char *argv[]) {
    int                sock;
    struct sockaddr_in server;
    //char               message[2000], server_reply[2000];

    //Create socket
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1) {
        printf(&quot;Could not create socket&quot;);
    }

    server.sin_addr.s_addr = inet_addr(&quot;127.0.0.1&quot;);
    server.sin_family      = AF_INET;
    server.sin_port        = htons(8888);

    //Connect to remote server
    if (connect(sock, (struct sockaddr *) &amp;server, sizeof(server)) &lt; 0) {
        perror(&quot;Connect failed. Error&quot;);
        return 1;
    }

    puts(&quot;Connected to server\n&quot;);
    int *new_sock;
    new_sock = malloc(1);
    *new_sock = sock;
    //keep communicating with server

    pthread_t send_thread, receive_thread;
    pthread_create(&amp;send_thread, NULL, sendMessage, (void *) new_sock);
    pthread_create(&amp;receive_thread, NULL, receiveMessage, (void *) new_sock);

    pthread_join(receive_thread, NULL);
    pthread_join(send_thread, NULL);

    close(sock);
    return 0;
}
You have to allocate sizeof(int) bytes for socket file descriptor, not 1
fflush(stdin) has undefined behavior
its not good idea to access a file descriptor in two threads simultaneously, be careful
joins are never happens, because none of two threads have exit conditions, so the socket will never close gracefully