I am working on a server, and when someone connects to my server I assign them an ID number. When they exit my server by typing QUIT, the ID number is released so that someone else can use the ID number.

My problem is... what if someone is disconnected from my server, like let's say their computer crashes and they disconnect without typing a QUIT command or their internet connection gets cut off? How can I make it so that when my program releases the socket, it also does other things like release the ID number, and print it to a log file, or carry out the same procedures that it would carry out if the user types QUIT to exit instead of disconnecting?

I am programming in MSVC++ .NET using the winsock2 library, so sends are carried out by send() and receives are carried out by recv() and so on...