Advertisement

Quick question about behaviour of CAsyncSocket::Listen

Started by October 03, 2003 11:25 AM
2 comments, last by Hoser 21 years, 4 months ago
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.
Advertisement
Listen returns immediately... By calling listen() you just set up the maximum amount of connections pending to be accepted at the same time (you can call it "connection slots")...
Thanks for the replies.

This topic is closed to new replies.

Advertisement