Re: Basic Socket
Lamefif <Leonardo.Pjetri@googlemail.com> wrote:
well no, i amended the code to what you suggested, ie WSAAsyncSelect()
before listen():
WSAAsyncSelect (s, hwnd, MY_MESSAGE_NOTIFICATION, (FD_ACCEPT
FD_CONNECT |FD_READ | FD_CLOSE));
int tempi = listen(s, SOMAXCONN);
//Don't forget to clean up with CloseConnection()!
closesocket(s);
MessageBox(NULL,"Done Listening ", "Got Request..", MB_OK);
listen returns 0 i.e no errors, that means a connection has happened
right?
No. Since you now call WSAAsyncSelect first, the socket is now in
non-blocking mode, so listen() returns immediately (which was the whole
point of the exercise). When the connection does arrive, you would get
MY_MESSAGE_NOTIFICATION message.
However, you still close the socket right after listen() returns, so of
course no connection arrives (you are no longer listening for them) and
thus no notification.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925