When is a good time to close socket



Is there a way to know when the socket has complete transfer of all data?
I am closing the as soon as send() has reported sending that last data. I
have read that this does not
necessarily mean that the transfer is complete but I cannot find how to test
for the condition.
If I put a Sleep(1000) after sending the last data it works. But this is
messy.
thanks


.