title: C++ server side not blocking on listen()
body: <p>The code below doesn't block on listen(), it just finishes execution. Could you tell me why? (initWSA returns true, I checked it). I'm following a tutorial and I was told it should block because it's looking for clients to connect.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;WinSock2.h&gt;
  
  #pragma comment(lib, "ws2_32.lib")
  using namespace std;
  
  #define PORT 10000
  bool initWSA(){
      WSADATA wsadata;
      int error = WSAStartup(0x0202, &amp;wsadata);
      if (error) return false;
      if (wsadata.wVersion != 0x0202){
          WSACleanup();
          return false;
      }
      return true;
  }
  void closeConnection(SOCKET s)
  {
      //Close the socket if it exists
      if (s)
          closesocket(s);
  
      WSACleanup(); //Clean up Winsock
  }
  int main(){
      initWSA();
      SOCKET s;
      SOCKADDR_IN addr;
      addr.sin_family = AF_INET;
      addr.sin_port = htons(PORT);
      addr.sin_addr.s_addr = htonl(INADDR_ANY);
      s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if (s == INVALID_SOCKET) cout &lt;&lt; "INVALID SOCKET" &lt;&lt; endl;
      if (bind(s, (LPSOCKADDR)&amp;addr, sizeof(addr)) == SOCKET_ERROR){
      cout &lt;&lt; "SOCKET ERROR" &lt;&lt; endl;
      }
      listen(s, SOMAXCONN);
      //cout &lt;&lt; "CAUGHT ONE" &lt;&lt; endl;
      //closeConnection(s);
      return 0;
  }
  </code></pre>