Quick question about behaviour of CAsyncSocket::Listen
I just had a quick question about the behaviour of the Listen method in the CAsyncSocket class.
When I call Listen, will the function return right away, or does it wait for an attempted connection before returning?
If it doesn''t return right away, is there a way to get it to stop listening?
Basically, I''m trying to right a very basic and small program that can accept a few connections. My thought was to have a separate thread running something along the lines of (just the basics)
threadfcn()
{
while (available connections)
{
Socket.Listen();
if (noerror)
Socket.Accept(blah blah blah);
}
}
Any comments would be great.
Thanks
(Assuming Windows here)
When your AsyncSocket is set to be non-blocking, listen doesn''t wait for a connection. It silently listens for connections in the background, and sends a Windows message to your app when a client connects to it.
Then you just process the message, and accept the connection as you wish.
I am relatively new with winsock programming, so I have no idea if this is an effective way to handle tons of connections. Check out the articles here on GameDev.net, there are a few good ones about asynchronous sockets.
When your AsyncSocket is set to be non-blocking, listen doesn''t wait for a connection. It silently listens for connections in the background, and sends a Windows message to your app when a client connects to it.
Then you just process the message, and accept the connection as you wish.
I am relatively new with winsock programming, so I have no idea if this is an effective way to handle tons of connections. Check out the articles here on GameDev.net, there are a few good ones about asynchronous sockets.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement