title: Recv() on a socket() not Receiving somehow (embedded Linux c/c++)
body: <p>Currently I have a client/server implementation of C code. I have done a lot to follow different books and implementations, and ultimately it doesn't work. </p>
  
  <p>Referencing the "printf" statements below, I can say that the client succeeds in sending the message, but the server never passes the receive stage (even after the client has supposedly succeeded in sending).</p>
  
  <p>So ultimately I get the impression that there is something either with the way my server is receiving the code OR something to do with the formatting what I am sending (when I say this I mean that I am possibly missing \0 or \r\n or something though I believe I am including them quite anally).</p>
  
  <p>Here is the relevant code with much removed:</p>
  
  <p>SERVER:</p>
  
  <pre><code>int Server::update(char *getbuf)
  {
  
  ...
  
  // ACCEPT
          clientsocket = accept(serversocket, (struct sockaddr *)&amp;client_address, &amp;alen);
  if(!clientsocket)
              logger.fail("Accept Fail");
  else
  logger.info("Accept succeed");
  
  
      z = recv (clientsocket, sbuf, sSize, MSG_DONTWAIT);
  
  
      snprintf(&amp;sbuf[z], sSize-z, "\r\n\0");
  
  
      snprintf(getbuf, sSize, sbuf);
  
  
      logger.data("Received: %s",sbuf);       
  
          respond(getbuf);
  
          return TRUE;
      }
  
  returnFALSE;
  }
  
  
  void Server::respond(char *response)
  {
  // SEND
  ssize_t z;
      int sSize = 64;
      char sbuf[sSize];
  
  
      snprintf(sbuf, sSize, response);
      snprintf(&amp;sbuf[z], sSize-z, "\r\n\0");
  
  
      z = send(clientsocket, sbuf, sSize, 0);
      if (z &lt; 0)
  fprintf(stderr,"send failure\n");
      else
  logger.info("Send Succeed");
  }
  </code></pre>
  
  <p>CLIENT</p>
  
  <pre><code>Code:
  
  int main(int argc, char **argv)
  {
  ...
  
      z = connect(com_socket, (struct sockaddr *) &amp;server_address, sizeof(server_address));
      if(z == -1)
      {
          if(errno == EINPROGRESS)
          {
              fprintf(stderr, "EINPROGRESS non block start\n");
          }
  
          if(errno == EALREADY)
          {
              fprintf(stderr, "EALREADY non block subsequent request\n");
          }
  
          fprintf(stderr, "Connect failed\n");
      }
      else 
      printf("Connect Success\n");
  
  
      int sSize = 64;
      char sbuf[sSize];
  
  
      z = snprintf(sbuf, sSize, command);
          snprintf(&amp;sbuf[z], sSize-z, "\r\n\0");
  
  
  // SEND
      z = send(com_socket, sbuf, sSize, 0);
      if (z &lt; 0)
          fprintf(stderr,"send failure\n");
      else
      printf("Send Succeeded\n");
  
  // READ
      z = recv(com_socket, sbuf, sSize, MSG_DONTWAIT);
      if (z &lt; 0)
          fprintf(stderr,"receive failure\n");
      else
      printf("Receive Succeeded\n");
  
      snprintf(&amp;sbuf[z], sSize-z,"\r\n\0");
  
  
  // Output
      printf("Received Response: %s\n", sbuf);
  
      close(com_socket);
  
      exit(1);
  }
  </code></pre>