[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Question about terminating server prog after idle time

Posted on 2005-04-23
2
Medium Priority
?
176 Views
Last Modified: 2010-04-15
Hello,

I am working on a simple socket program in which a server holds a username-password database, and then clients can connect to it and check combinations.  The problem is, the server is supposed to terminate after 50 seconds of idle time (no clients connecting to it) and I am not sure how to be watching time while waiting for a connection.  I am programming in C in a Unix environment.

Thanks
0
Comment
Question by:Tim_Heldberg
  • 2
2 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 750 total points
ID: 13852307
You can use alarm() ...

alarm(50);

this will send a SIGALRM to your program after 50 seconds ... You will have to write a signal handler for SIGALRM .. use sigaction interface to do that

man sigaction
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 13852320
Check these links
http://www.scit.wlv.ac.uk/~jphb/comms/sockets.html#recv
http://users.actcom.co.il/~choo/lupg/tutorials/signals/signals-programming.html#timers

The second link uses signal() interface ... This is outdated and now has been replaced with sigaction which is more sophisticated but the basic idea remains the same ... Also, the example there uses gets() .. avoid gets too .. read the notes/bugs section of man gets for more information.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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