timeout for handshake

This is a discussion on timeout for handshake within the C++ Programming forums, part of the General Programming Boards category; im writing some simple networking software, the first version is just serial and parallell support. i open the host port ...

  1. #1
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385

    timeout for handshake

    im writing some simple networking software, the first version is just serial and parallell support. i open the host port and open the guest port. After 3 seconds (allow time for port to init) the guest states its network name and id and encryption set. The other machine then basically sends an ack back. But i want some sort of timeout loop where if after x seconds the data is not sent the host can request it. But i also need to continually poll the port to check for data, how can i set up a simple timing loop?
    Windows Console Win9x BCCB3
    tia
    Monday - what a way to spend a seventh of your life

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    Code:
    #include <time.h>
    
    time_t startT = time(NULL);
    bool gotData = false;
    do
    {
        //wait for sender to send data
        //send ack if needed
       if( the data was recieved)
          gotData = true;
    }while( (!gotData) && (time(NULL) - startT ) < 10000 ); //this will wait 10 secs, but exit the loop if the data was already recieved
    if( ! gotData )
    {
       //send request;
    }
    else
    {
       //you got the data!!!
    }
    time_t time( time_t * t ) returns the time in milliseconds.
    1000 milliseconds = 1 second
    You can pass it a pointer to a time_t data type and it will store the current time there, as well as returning it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  2. how to setup C# TCPClient timeout
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-13-2007, 01:09 PM
  3. rsh timeout
    By jlai in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 08:18 AM
  4. connect timeout
    By X PaYnE X in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-14-2005, 10:30 PM
  5. NFS timeout problem
    By rotis23 in forum Linux Programming
    Replies: 3
    Last Post: 10-20-2003, 04:02 PM

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