How to Identify "if a UDP socket did not receive any packet in a certain time interval".

Posted on 2004-11-15
Last Modified: 2010-03-31

 The following line of code exists in my program
 where dp is a datagram packet, d is a datagram socket.

  Now, my program waits for a packet to arrive and then depending on what arrived the rest of the program depends., but what i want to do is if this socket does not receive any packet for a certain interval of time , say 5seconds, i want to perform some other task. The difficulty is how do i get out of this line of code, when i dont receive any packet for the predefined interval of time ( and understand that it came to the next line because of "not receiving any packet for 5 seconds"). It just simply does not come out of that line until it receives a datagram packet.

 Thanks and regards,
Question by:prashanth_gurijala
    LVL 92

    Expert Comment

    set a timeout for the socket:



    Author Comment

    ok, but when the timeout occurs, how will i find out that, it came out of that statement because of timeout.....
    LVL 92

    Accepted Solution

    a SocketTimeoutException will be throw

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    FizzBuzz challenge 9 64
    seriesUp challenge 7 80
    Fibonacci challenge 11 61
    stringclean challenge 26 43
    For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now