Thread: C Programming: give command a 5 sec interval to run

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    1

    C Programming: give command a 5 sec interval to run

    Hi all,

    I am new to C and I need some help solving an issue with network programming.
    So in general, i have two programs running: Program A and Program B.

    Description of A:
    Send out packet with SN = i
    (SN is the label for the packet. i.e first pkt SN=1, 2nd pkt SN=2 etc)
    Set timer
    If RN=x is received from B, and x=i+1, set SN=i+1.
    (RN is label for packet coming back from B)
    Otherwise, ignore.

    If timer expires, resend pkt SN=i
    Reset timer
    and repeat.

    Description of B:
    Send out packet with RN = j
    Set timer
    If SN=y is received from A, and y=i, set RN=i+1.
    Otherwise, ignore.
    repeat

    In short, these two programs are just loops. A needs to receive an acknowledgment from B to proceed to the next state, otherwise resend the current packet. And for B, if B received a packet from A, it will send an acknowledgment to A telling it to move on to next state.

    My problem is with the "Set timer" part. So this part is supposed to allow about 5 seconds for each program to receive pkt. For those who know how to use the select() function, I want something similar select() except it will watch over an integer (like SN and RN) instead of just a socket.

    Thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You could use sleep(number of seconds), or Sleep(ditto). One or the other should be available on your system

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    1
    Hi!!
    Only option is sleep as mentioned by "Adak".
    I never done in C language but used in JAVA programming.
    I don't have idea about the sleep function of C.
    Sorry for that but yes you JAVA provides this function and I did the mentioned hand shake program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 3
    Last Post: 11-16-2009, 07:51 AM
  3. Dev C++: can't run code
    By blurrymadness in forum C++ Programming
    Replies: 0
    Last Post: 08-07-2009, 07:33 PM
  4. triggering another program to run using serial port
    By infineonintern in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2009, 05:16 AM
  5. Replies: 2
    Last Post: 02-28-2002, 12:40 PM