Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keeping track of logged in users

Status
Not open for further replies.

sillysod

Technical User
Jan 6, 2004
300
GB
I need to keep a track of how many users are logged into my software so that i can prevent some settings being changed while other users are logged in.

How can i keep track of user logins on the server? so i can see who is logged in at any one time and how many users are active?

I have thought about doing this by having a SQL table and creating a record when you log in and deleting the record when the app is closed, however if the system crashes out i will get records for users who are not actually in the system and have no way of verifying whether that user is actually logged in or not.

does anyone have any suggestions ?
 
How are the users using/connecting to your app?

Is it a tcp server app? If so, what method are you using to manage multiple connections (array...)?

I have a similar situation with a piece of software, I created a connection array class so that I can check how many users are connected (simple array.Count) and when a connection is closed or timed out (30-60 sec) the class removes the connection from the array...

If you can provide some more information on how your app works, I will be able to help you a bit more...
 
its just a simple database app using SQL Server.

does that help or do you need more info?
 
A bit more info would be useful...

My suggestion is to store the connected clients in an array, and update the array when clients connect or disconnect.

The array would then show the actual activity, because the array would be empty if your app crashes and restarts.

An array would also be faster, because you wouldn't need to request the data from the db. Querying the array for the number of current client would only need a single line "array.GetLength" or with an ArrayList "array.Count".

I would use an ArrayList because you can use the functions to Add and remove without resizing the array (saves on lines of code).

 
Hmm, not sure i follow

wouldnt the array be stored on the local machine? and therefore wouldnt be able to keep track of clients logging on from other machines?

The users will use the client app installed locally on their machine. all the clients then share a central SQL server.

So i need to be able to see from the app how many users on other machines have the app open.

if i wrote a small app that sits on the server, is it possible for the client to register with that app when its opened and have the server app check periodically to see if the software is still active on the clients machine?

 
Ok, I thought you had a server side app...

You could use a time out feature to what you are already doing. The client app could then update their log record every 20 sec for example, and if they disconnect without deleting the record, it would be 20-30 seconds out.

1) Client adds log record, with time stamp
2) Client updates record setting the time stamp to the current datetime every 20 seconds.
3) When the log needs checking, use something like: "SELECT * FROM ClientLog WHERE TimeStamp > '" & DateTime.Now.AddSeconds(-30) & "'"
4) Clear (maintenance) the log using: "DELETE FROM ClientLog WHERE TimeStamp < '" & DateTime.Now.AddSeconds(-30) & "'"
5) Client logs off, removes the record

Hope this is understandable and helps
 
Cheers for the reply.

Last night i have a play around with udp and wrote a little server app.

when client logs on it sends a udp message saying user x has logged on.

The server app then adds an entry to a listview.

The problem i have found with that is the server app doesnt "acknowledge" the udp messahe, so i hit a wall when i realised i couldnt check that the server app is running and has acknowledged the log in.

The idea was that the server app would have a function to verify all users, so if a user did crash out i could periodically run the function and the server app would send out a udp message to each client and check the client is still running.
 
I will have another look at the UDP stuff tonight, but if i fail i have the SQL table option to fall back on.

My only concern is that if i run suich a query every 20 seconds is it going to slow things down when the app is also doing other database tasks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top