When socket_close() is called?

When a program using sockets is stopped, all remaining open sockets are closed.
However it is good practice, to use socket_close() yourself to ensure proper housekeeping.