![]() |
| | #1 |
| Registered User Join Date: Mar 2009
Posts: 35
| Server for an iterative client When a socket is created, by default it is a blocking socket. Under blocking mode socket I/O operations, connect and accept operations all block until the operation in question is completed. I want to receive data periodically from a client. That is, the first time I receive data the socket is blocked in the accept function but the next time is not blocked anymore and I want that it waits for the next incoming data. Do you know what can I do? thank you |
| radeberger is offline | |
| | #2 | |
| critical genius Join Date: Jul 2008 Location: SE Queens
Posts: 5,228
| You can set and unset O_NONBLOCK on a socket file descriptor with fcntl(). The only possible purpose for using non-blocking mode is because you DO NOT want it to wait, so this: Quote:
If you mean you have a number of clients and you want to make sure to check them all, either use select() or you can use a series of accept()/recieve()'s on a NONBLOCK socket in an infinite loop BUT MAKE SURE YOU PUT A SMALL TIME DELAY IN, otherwise that loop will max the CPU out infinitely. | |
| MK27 is online now | |
| | #3 |
| Registered User Join Date: Mar 2009
Posts: 35
| Hi again, thank you for the answer But I NEED TO WAIT because I don't know how long does it take until the client have the next block of data, therefore I want the socket to wait at the accept function. And that works for the first data but for the rest it doesn't work. I have only one client. It send me packets periodically. |
| radeberger is offline | |
| | #4 |
| Registered User Join Date: Apr 2008
Posts: 282
| I think you have the wrong idea about accept() and what you're really looking for is recv*(). accept() blocks until a tcp clients connects, once it is connected, there is no need to use accept() again except if you're obviously waiting for another client to connect. However recv() will block each time you wait for data from the connected client (if you didn't use O_NONBLOCK). For a given client, there is only one accept() and multiplex recv()/send(). |
| root4 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| server client application - (i really need your help) | sarahnetworking | C Programming | 3 | 03-01-2008 10:54 PM |
| Socket Programming Problem!!!! | bobthebullet990 | Networking/Device Communication | 2 | 02-21-2008 07:36 PM |
| Client works on a LAN but don't send all the data | Niara | Networking/Device Communication | 9 | 01-04-2007 04:44 PM |
| Where's the EPIPE signal? | marc.andrysco | Networking/Device Communication | 0 | 12-23-2006 08:04 PM |
| Unicode vurses Non Unicode client server application with winsock2 query? | dp_76 | Networking/Device Communication | 0 | 05-16-2005 07:26 AM |