I have a C ++ program using winsock2. I would like to know how to tell when someone will connect to my program.
Use select to wait for a read on a socket; when the socket is closed, winsock should report it as readable. After receiving from the socket, you will receive 0 bytes, informing you that the socket was closed.
int received_bytes = recv(_socket, buffer, sizeof(buffer)-1,0); if(received_bytes > 0) { //data received } else if (received_bytes == 0) { //connection closed } else { //wait for more data }