From MSDN:
WSAENOTSOCK (10038)

Socket operation on non-socket.

An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket, or for select, a member of an fd_set was not valid.
I'd recommend you to first test MSDN example without your own changes.
Only after it will work - try to change it according to your needs!