Timed Server Events

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I have a server (NT service) that listens on multiple ports, some use
asynchronous methods and some synchronous methods for reading and writing to
and from the sockets.

I could really benefit from timed server events. For example, say I wanted
to disconnect a user who has idled at a login prompt for over 3 minutes. Or,
to perform some maintenance after a week has passed. Or, limit sessions by a
specified time frame.

I am wondering, what is the best and most efficient solution to achieving
this? I have solved it using various methods (such as threads running in
infinite loops, a shared timer created in its own thread, etc). But I am
just wondering what is the most efficient solution from the opinions of
developers.

Previously, I used socket time outs (each socket would time out after a half
a second while waiting for data, then it would wait again) which was very
efficient since it had to be done anyway. During each time out, I would
check time stamps to see if a specified time frame has elapsed. This was
great, but now I handle sockets at a much lower level so it is not feasible
to do anymore.

A timer for each user or each socket would not be feasible either, since
there are potentially hundreds of users connected at any given time.

So, any ideas on what the best possible practice may be?

Thanks so much in advance.
 
Maybe it will be better to implement a class lets call it Monitor which will
observe all the connections and then record the information about each
connection. After some specified timeout Monitor will check, depending on
conditions, these records and then perform some actions e.g disconnect user.

The good side of this implementation is that all the logic of timeouts
handling will be on one class.
 
That's what I was thinking. Since there are multiple server ports (and
services connected to the service application), that one class would have to
iterate through potentially hundreds of users on different services every
second (let's say) to see if anything needs handled though. Plus Monitor
would have to have access to public methods. I'm not sure I like that.

One thing I was thinking about was to have one static timer per
service/server port, and have that iterate through all the connected users
of its kind that way there are separate monitors for each service and they
only have to iterate through their own groups. And then the timer could shut
itself off if no one is connected so we're not checking anything needlessly.
How does this sound? Can anyone think of anything even more efficient?

I appreciate all the help!
 
Back
Top