![]() |
| | #1 |
| Registered User Join Date: Jul 2006
Posts: 63
| What exactly does listen() do from winsock 1.1 Code: //define the listening socket above listen(listenSock, 10) //define a server socket serverSock = accept(listenSock, NULL, NULL); //terminate server thread, as this is just a test So what does listen() actually. Im really confused, as i was intending to make a loop using listen to block until a client tried to connect and then launch a thread. But it would appear as though listen did more than just block. Could someone please explain whats going on there. Thanks. |
| *DEAD* is offline | |
| | #2 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| listen() puts the socket in listening mode. It doesn't wait for an actual connection, though. That's accept()'s job.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #3 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| listen() goes in the main thread, then you pass the accept()'ed socket into a new thread to deal with that connection. The main thread loops round for another listen.
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
| | #4 |
| Registered User Join Date: Jul 2006
Posts: 63
| ok, so accept() will block and should be in the loop, and theres some sort of magical queue created in the background. I hate magic, so confusing. Thx, im pretty sure i can work from there. |
| *DEAD* is offline | |
| | #5 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| There's no queue. Accept will block if the socket is blocking and won't if it's not. Where is this queue you are speaking of? |
| Bubba is offline | |
| | #6 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| This queue is internal to the network driver and holds client connections until accept fetches them.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #7 |
| Super Moderator Join Date: Aug 2001
Posts: 7,472
| Ok there's no queue from a software standpoint. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| (C++) Winsock connect and listen program. Need Help! | azjherben | Networking/Device Communication | 2 | 04-05-2009 07:44 PM |
| Winsock issues | tjpanda | Windows Programming | 3 | 12-04-2008 08:32 AM |
| Winsock: Cutting A listen() Call Short | SMurf | Windows Programming | 2 | 10-05-2006 12:02 PM |
| Where do I initialize Winsock and catch messages for it? | Lithorien | Windows Programming | 10 | 12-30-2004 12:11 PM |
| Non blocking listen() with winsock | manwhoonlyeats | C Programming | 1 | 12-08-2002 07:00 PM |