If Winsock reports that the socket has been closed, or that there has been an error, mIRC will feed that back to the script. How are you detecting that the socket has been closed? During a sockwrite/sockread/sockclose event? Is an error reported?