i have a simple server that accepts clients.
The client connect to the server. The first thing the server will do the following:
- grab the client socket
- create a thread for client
- call ::recv();
the problem here is that recv returnes -1
WSAGetLastError returnes WSAENOTSOCK: (Socket operation on nonsocket.) Microsoft: “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 can’t really figure out what the problem really is.
the client has the socket still valid , and any recv the client dose will instantly return
Thanks, Raxvan
OK, that’s easy.
In your code, you have
that returns a
sokby value.Here you assign it to a local variable:
and at the end of this expression, the temporary
sokreturned from Accept() gets destroyed. You might want to put a breakpoint or a debug print insok::Close()to see what I mean with your own eyes.