Re: Basic Socket
"Lamefif" <Leonardo.Pjetri@googlemail.com> wrote in message
news:1191583661.005808.64500@19g2000hsx.googlegroups.com
im following this article here not quite getting it to work :(
http://www.codeproject.com/internet/beginningtcp_cpp.asp
the problem is i dont' seem to be getting any of these events
FD_ACCEPT | FD_CONNECT |FD_READ | FD_CLOSE
i've set it up so that every time a key is pressed the ListenOnPort()
is called.
Why? You only ever need to set up listening socket once (to be exact,
once for every port you want to be listening on).
int tempi = listen(s, SOMAXCONN);
WSAAsyncSelect (s, hwnd, MY_MESSAGE_NOTIFICATION, (FD_ACCEPT |
FD_CONNECT |FD_READ | FD_CLOSE));
You have to call WSAAsyncSelect _before_ listen. Otherwise, the socket
is still in blocking mode and listen() doesn't return until there's an
incoming connection.
//Don't forget to clean up with CloseConnection()!
closesocket(s);
Well, you can't close a socket and still hope to receive asynchronous
notifications from that very socket, can you?
--
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