Sockets end in state eCLOSE_WAIT

I finally found time to solve the above mention problems in PR #559.

It also addresses the issues mentioned in this post.

Thank you for reporting and for helping to find a solution.