TIMOB-14874-Check for closed state before closing the socket again

Test case looks ok to me, it is that the 'closed' state is not properly checked before closing the socket again.

https://jira.appcelerator.org/browse/TIMOB-14874