1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Sockets, multiple clients

Discussion in 'C' started by guyov, Mar 30, 2010.

  1. guyov

    guyov New Member

    Joined:
    Mar 30, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hey,
    I am trying to implement a channel, which receives packets from multiple clients.
    I want to check the packets I get in a specific time interval each time (100 milliseconds).
    If I get more than 1 packet, I need to send to all the clients an error packet, if I get
    only 1 packet, I will forward it to the relevant server.

    Any idea on how to implement that "receiving on time intervals"?

    Thanks!
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Depends how accurate it needs to be. You could sleep the process for 100ms, then do all the stuff on wakeup. Time per iteration will be 100ms plus processing time. So if it needs to be exactly 10 times a second, every second, best bet is to wakeup more frequently than that (say every 10ms) then check the system clock and see if it's 100ms later than the last time you did stuff: if not go back to sleep, if so then do the processing. You'll still get a bit of jitter this way but you can reduce the amount of jitter by reducing the sleep time. If it needs to be *exactly* every 100ms then you will need an RTOS.
     

Share This Page