C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 03-18-2009, 08:25 AM   #1
Registered User
 
Join Date: Mar 2009
Posts: 35
Server for an iterative client

Hi everybody,

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   Reply With Quote
Old 03-18-2009, 10:07 AM   #2
critical genius
 
MK27's Avatar
 
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:
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.
is non-sensical.
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.
__________________

"A man can't just sit around." -- Larry Walters
MK27 is online now   Reply With Quote
Old 03-18-2009, 11:22 AM   #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   Reply With Quote
Old 03-18-2009, 12:11 PM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 07:54 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22