title: recvfrom() returns error 10022 when passing socket handle to thread
body: <p>I'm working on UDP chat for programming classes. For now, I'm dealing with parallel in/out.</p>
  
  <p>So, I'm creating thread to receive messages from server:</p>
  
  <pre><code>// in-thread
  DWORD WINAPI in_thread(void* param)
  {
      int n; // variable receivefrom returned
      char buff2[1000];
  
      sockaddr_in client_addr;
      int client_addr_size = sizeof(client_addr);
  
      SOCKET my_sock;
      my_sock = (SOCKET)param; // casting from void* to SOCKET
  
      // reading server message
  
      while (1)
      {
          n = recvfrom(my_sock, buff2, sizeof(buff2) - 1, 0, (sockaddr*)&amp;client_addr, &amp;client_addr_size);
          // ......................
      }
  
      ExitThread(0);
  }
  </code></pre>
  
  <p>And socket handle goes from:</p>
  
  <pre><code>hThread = CreateThread(NULL, NULL, &amp;in_thread, (void*)sock, NULL, &amp;ThreadId);
  </code></pre>
  
  <p>But I am recieving:</p>
  
  <blockquote>
    <p>Error 10022: Invalid argument. (Returned by <code>rercvfrom</code>)</p>
  </blockquote>
  
  <p>Where could it have gone wrong?</p>
  
  <p>edit:</p>
  
  <p>If it goes without passing to CreateThread, it works fine.
  For example: </p>
  
  <pre><code>SOCKET sock; 
  // Opening socket 
  sock=socket(AF_INET, SOCK_DGRAM, 0); 
  int n; // variable receivefrom returned 
  char buff2[1000]; 
  sockaddr_in client_addr; 
  int client_addr_size = sizeof(client_addr); 
  n= recvfrom(sock,buff2,sizeof(buff2)-1,0, (sockaddr *) &amp;client_addr, &amp;client_addr_size); 
  </code></pre>
  
  <p>It works fine, socket works, no errors given, but when I pass it to createthread like in code in the question, error occures.</p>
  
  <p>Using VS10, winsock2 lib.</p>