title: Why is puts() function not printing mutiple output in client-server socket code?
body: <p>Here is my client-server code which works only for a single user at a time and the client can send as many messages as he wants.<p>
  I show the received message at the server and its reply (which is actually reverse of it) - and also the message "message sent".</p>
  
  <p>At client side I show the input message and the server reply: "message got"</p>
  
  <p>But there is a problem in my code: when I try to send multiple messages I get the right output at server side but not at client side, which is only "message got", but after that puts function it doesn't print any output to std-out. <p>I have tried many things but I haven't found a way to do it.
  <br>Is there any flushing to std-out or am I missing something?<br>
  Please tell me.</p>
  
  <p><code></p>
  
  <pre><code>server code::::::  
      #include &lt;stdio.h&gt;  
      #include &lt;string.h&gt;   
      #include &lt;sys/socket.h&gt;  
      #include &lt;arpa/inet.h&gt;     
      #include &lt;unistd.h&gt;   
      #include &lt;stdlib.h&gt;  
      int main(int argc , char *argv[])  
  {  
       int socket_desc , client_sock , c , read_size;
      struct sockaddr_in server , client;
      char client_message[2000];
  
  
      socket_desc = socket(AF_INET , SOCK_STREAM , 0);
      if (socket_desc == -1)
      {
          printf("Could not create socket");
      }
      puts("Socket created");
  
      //Prepare the sockaddr_in structure
      server.sin_family = AF_INET;
      server.sin_addr.s_addr = INADDR_ANY;
      server.sin_port = htons( 42969 );
  
      //Bind
      if( bind(socket_desc,(struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
      {
          //print the error message
          perror("bind failed. Error");
          return 1;
      }
      puts("bind done");
  
      //Listen
      listen(socket_desc , 3);
  
      //Accept and incoming connection
      puts("Waiting for incoming connections...");
      c = sizeof(struct sockaddr_in);
       while(1)
      {
      //accept connection from an incoming client
      client_sock = accept(socket_desc, (struct sockaddr *)&amp;client, (socklen_t*)&amp;c);
      if (client_sock &lt; 0)
      {
          perror("accept failed");
          return 1;
      }
      puts("Connection accepted");
      pid_t p=fork();
        if(p==0)
       {
         close(socket_desc);
      //Receive a message from client
      while( (read_size = recv(client_sock , client_message , sizeof(client_message) , 0)) &gt; 0 )
      {
          puts(client_message);   
      char message[20000];
      int i,j=0;
      for(i=strlen(client_message)-1;i&gt;=0;i--)
      message[j++]=client_message[i];
         message[j]='\0';
  puts(message);
          //Send the message back to client
         if( send(client_sock , message , sizeof(message),0)&gt;0)
                     puts("message sent");
         // memset(client_message,'\0',sizeof(client_message));
       //memset(message,'\0',sizeof(message));
      }
  
      if(read_size == 0)
      {
          puts("Client disconnected");
          fflush(stdout);
      }
      else if(read_size == -1)
      {
          perror("recv failed");
      }
  close(client_sock);
  exit(1);
  }
  }
        close(socket_desc);
      return 0;
  }
  
  
  
  
  client code::::
  
  #include&lt;stdio.h&gt;  
  #include&lt;string.h&gt; 
  #include&lt;sys/socket.h&gt; 
  #include&lt;arpa/inet.h&gt; 
  #include&lt;stdlib.h&gt; 
  
  int main(int argc , char *argv[])
  {
      int sock;
      struct sockaddr_in server;
     // char message[1000] ,
      char server_reply[2000];
  
      //Create socket
      sock = socket(AF_INET , SOCK_STREAM , 0);
      if (sock == -1)
      {
          printf("Could not create socket");
      }
      puts("Socket created");
  
      server.sin_addr.s_addr = inet_addr("127.0.0.1");
      server.sin_family = AF_INET;
      server.sin_port = htons (42969 );
  
      //Connect to remote server
      if (connect(sock , (struct sockaddr *)&amp;server , sizeof(server)) &lt; 0)
      {
          perror("connect failed. Error");
          return 1;
      }
  
      puts("Connected\n");
  
      //keep communicating with server
      while(1)
      {
          printf("Enter message : ");
       char message[1000];
          scanf("%s" , message);
          //Send some data
          if( send(sock , message , sizeof(message) , 0) &lt; 0)
          {
              puts("Send failed");
              return 1;
          }
  
          //Receive a reply from the server
          if( recv(sock , server_reply , sizeof(server_reply) , 0) &gt; 0)
          {
              puts("message got");
  
          }
  
          puts("Server reply :");
          puts(server_reply);
  fflush(stdout);
   //memset(server_reply,'\0',sizeof(server_reply));
       // memset(message,'\0',sizeof(message));
      }
  
      close(sock);
      return 0;
  }
  </code></pre>
  
  <p></code></p>