wait X seconds implementation

This is a discussion on wait X seconds implementation within the Linux Programming forums, part of the Platform Specific Boards category; I have an UDP server and I need to close connection to a client after 10 seconds . How can ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    wait X seconds implementation

    I have an UDP server and I need to close connection to a client after 10 seconds . How can I implement that ? ... C under linux
    Last edited by ghostdlr; 02-15-2010 at 04:12 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You can use a timer:

    SourceForge.net: POSIX timers - cpwiki

    and then sleep() before you close() the socket descriptor in your UDP server.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You could also set a timeout on the socket, depending on what you're doing with the socket though.

    But waiting 10 seconds and doing nothing, then closing the socket doesn't make much sense.

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,236
    Quote Originally Posted by ghostdlr View Post
    I have an UDP server and I need to close connection to a client after 10 seconds . How can I implement that ? ... C under linux
    You can't, since there's no such thing as a UDP connection.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hey excellent point.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-18-2010, 10:17 AM
  2. clock ticks vs time.h
    By underthesun in forum C Programming
    Replies: 3
    Last Post: 01-26-2010, 10:46 AM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. How to build a timer that counts the seconds elapsed?
    By Nazgulled in forum C Programming
    Replies: 17
    Last Post: 05-28-2007, 12:26 PM
  5. Time to seconds program
    By Sure in forum C Programming
    Replies: 1
    Last Post: 06-13-2005, 08:08 PM

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