// init stuff.
.
.
.
listen();
// now the listener socket is listening.
for(; {
accept();
// accept() will block until there is a new connection.
// when new connection arrives, notify the main thread
// and pass it the fd # for the new connection.
}
Thanks,
-yuki
listen() and accept() question
I am not quite sure how listen() works. Once you call listen() on a listening socket, does it KEEP listening forever until you, say, close() the socket?
Or does it listen only when listen() is called? Which in that case I would need to put it in a loop to keep listening.
if the aforementioned is the case, then would this structure work:
-forseti
You only need to listen() once. listen() puts the socket into a listening state, ready for connections. You can then do accept() to accept a connection (or wait if theres no connection ready). If you want to test for a connection, use select(), and test for a read operation with a timeout of zero seconds, 0 miliseconds.
Edit: Yep, that code will work fine - so long as you remove the smiley![](tongue.gif)
![](http://www.cee.hw.ac.uk/~ceesm6/Pics/StevesSig.gif)
[edited by - Evil Bill on January 6, 2003 10:11:20 PM]
Edit: Yep, that code will work fine - so long as you remove the smiley
![](tongue.gif)
![](http://www.cee.hw.ac.uk/~ceesm6/Pics/StevesSig.gif)
[edited by - Evil Bill on January 6, 2003 10:11:20 PM]
Member of the Unban Mindwipe Society (UMWS)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement