![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Jul 2006
Posts: 63
| How to initialize a non blocking socket using only winsock library Also, just out of curiosity, is a socket set as blocking/non blocking when the socket is initialized (ie socket is called), or can it be changed, say, in between two recv() calls. Thx again |
| *DEAD* is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| As far as I understand [given that I haven't ever done socket programming], you use select to check if a socket will block. You can then safely call recv() to fetch some data on a particular socking, knowing that the call will NOT block. Is that what you wanted to know? -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Jul 2006
Posts: 63
| Well, i think your talking about what happens with non-blocking sockets once they have been initialized. If you call recv and the call wouldblock, then it returns a blocking error and you must parse that and move on with the program. |
| *DEAD* is offline | |
| | #4 |
| Registered User Join Date: Dec 2007
Posts: 6
| When you create a socket it is automatically set to be blocking. If you want to set it to non blocking then you can call fcntl, i.e. Code: fcntl(sockfd, F_SETFL, O_NONBLOCK); I highly recommend you use the select method which can monitor a set of sockets and when there is an event on one of them you can then determine which one it is and work with it. You can also add a timeout interval on select so if no event is received on the sockets during that time interval then it carries on with program execution. Let us know if you need any help using select. It is relatively easy. Hope this helps |
| Codeslinger is offline | |
| | #5 |
| Unregistered User Join Date: Sep 2005 Location: Antarctica
Posts: 341
| maybe what you are looking for is the select() function? Here's a link that may help: http://tangentsoft.net/wskfaq/exampl...ct-server.html
__________________ -- Rocky -- DreamSys Software (http://www.dreamsyssoft.com) -- Free Tiff 2 PDF Library (http://www.dreamsyssoft.com/tiff-to-pdf-api) |
| rockytriton is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Nonblocking socket...blocking? | zolom | Networking/Device Communication | 2 | 07-13-2009 12:06 PM |
| very weird .h problem | royuco77 | C++ Programming | 1 | 09-11-2005 07:55 AM |
| Where do I initialize Winsock and catch messages for it? | Lithorien | Windows Programming | 10 | 12-30-2004 12:11 PM |
| problem closing socket | Wisefool | Networking/Device Communication | 2 | 10-29-2003 12:19 PM |
| C++ Socket Library | iron | C++ Programming | 1 | 06-28-2002 09:01 AM |