The call to listen
only places the socket in a state that accepts incomming connections. In order to actually accept a connection, you need to call the accept
function. The call to accept
blocks the program until you get a connection.
SOCKET ClientSocket = INVALID_SOCKET;
// Accept a client socket
ClientSocket = accept(sv, NULL, NULL);
if (ClientSocket == INVALID_SOCKET) {
printf("accept failed: %d\n", WSAGetLastError());
closesocket(sv);
WSACleanup();
return 1;
}