Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 815787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:44:16+00:00 2026-05-15T01:44:16+00:00

Hey I was writing a udp client server in which a client waits for

  • 0

Hey I was writing a udp client server in which a client waits for packets from server.But I want to limit this wait for certain time.After client don’t get response for a certain moment in raise an alarm,basically it comes out and start taking remedy steps.So what are the possible solution for it.I think writing a wrapper around recv will work but how exactly this has to be done,I mean how will make recv raise alarm for you after that time limit.

Any Help in this regard will be appreciated.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T01:44:17+00:00Added an answer on May 15, 2026 at 1:44 am

    If you want to do socket communications with timeouts, then select is the way to go.

    You basically set up arrays of file descriptors for various events such as read-ready or write-able, then call select with a timeout. If one of the events is valid, you will be notified and you can perform your actions.

    If none of the events occurs before the timeout, you’ll still be notified and can take whatever remedial action you see fit.

    See here for the gory details, expanded on below.

    Alternatively, you can use setsockopt with the SO_RCVTIMEO:

    struct timeval tv;
    tv.tv_sec = 5;
    tv.tv_used = 0;
    setsockopt (socket_id, SOL_SOCKET, SO_RCVTIMEO,
        &tv, sizeof(struct timeval));
    

    For details on select, you use the FD_ZERO and FD_SET macros to construct a set of file descriptors (fdsets) of interest to you. You can have three sets, one indicating whether one or more fds has data to read, one indicating whether one or more is ready for writing to, and one indicating errors. You may not necessarily have all three, it depends on what your code is doing.

    Once you’ve set up the fdsets, you pass them, along with the number of fds and a timeout, to select which weaves its magic and returns to you. Before you do this, make a copy (FD_COPY) of the fdsets for later recovery.

    On return, there’s either been an error, timeout or an event pertaining to one of the fds of interest. In that latter case, the fdsets have been modified to only have the fds set for those with an event and you can use FD_ISSET to detect which ones.

    Then, once you’ve handled all the events, use FD_COPY to restore the original fdsets (they were modified by select, remember) and call select again. Continue for as long as you need to.

    Keep in mind that an error return from select is not necessarily fatal. You can get (in errno) EAGAIN for a temporary resource shortage or EINTR if a signal was handled. For that second case, you can just re-enter the select call. For the first, I’d implement a retry loop in case it was just a temporary thing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey I'm writing on an Server-Client program but when my client sends something, it
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
Hey im writing an echo client, and for some reason the connectsock function is
Hey. i am writing a forum, and i have this table that marks messages
Hey so what I want to do is snag the content for the first
Hey all, my Computational Science course this semester is entirely in Java. I was
Hey, I've been developing an application in the windows console with Java, and want
hey im writing a c# flv2mp3 converter and i could need some help. flv
Hey--I'm writing a basic Rails app that uses the digg API. I'm trying to
Hey I am writing an app in Twisted, and as it stands I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.