title: recv() returns always 0
body: <p>I've a problem with <code>recv()</code> function that I can't explain: it always returns 0. I've a client/server application in which the server simply has to receive a string from the client through the internet (different pc). <br>There are no connectivity problems, and I also tried to send a string from server to client: it worked.
  I search in the blog and what I found, <a href="https://stackoverflow.com/questions/3091010/recv-socket-function-returning-data-with-length-as-0">recv() socket function returning data with length as 0</a>, <a href="https://stackoverflow.com/questions/17824865/non-blocking-recv-returns-0-when-disconnected">non-blocking recv returns 0 when disconnected</a>, <a href="https://stackoverflow.com/questions/23866637/recv-returning-zero-incorrectly">Recv returning zero incorrectly</a>, didn't help me to understand.</p>
  
  <p>Here I post the Network class:
  Network.h</p>
  
  <pre><code>    class Network
      {
          WSADATA wsaData;
          WORD wVersionRequested;
          int Port;
          unsigned int byteReceived, byteSent; 
          SOCKET listeningSocket, connectedSocket; 
          SOCKADDR_IN serverAddr, senderInfo, clientAddr;
          int caddrlen;
  
      char buff[DIM];
      string buffer;
      public:
          Network();
          ~Network();
  
      void Recv();
  };
  </code></pre>
  
  <p><br>Network.c</p>
  
  <pre><code>void Network::Recv() {
      int n = recv(connectedSocket, buff, strlen(buff), 0);
  
      setByteReceived(n);
      buffer.assign(buff, n);
      cout &lt;&lt; "Buffer is: " &lt;&lt; buff &lt;&lt; endl; 
      if (byteReceived == 0)
          cout &lt;&lt; "\tConnection closed" &lt;&lt; endl;
      else if (byteReceived &gt; 0) {
          cout &lt;&lt; "\tByte received: " &lt;&lt; byteReceived &lt;&lt; endl;
          cout &lt;&lt; getBuffer() &lt;&lt; endl;
      }
      else {
          myFormatMessage(WSAGetLastError());
      }
  }
  </code></pre>
  
  <p><br>
  The behaviour in the end is the following: client and server are connected, the server returns 0 from recv(). I tried also to run both programs on the same machine. Thank you for your help.</p>