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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting instances of running apps 1

Status
Not open for further replies.

paulhmorris

Programmer
Sep 19, 2002
14
GB
How can I tell how many instanvces of my delphi appliaction is running on a lan
 
Are you connecting to a database ?
If you are and its something like SQL Server you can get a count of the number of connections with the appropriate application name (assuming you've set it).
Hope this helps.
Steve
 
Maybe you could have your program create a textfile with random name at start up, and delete it on close. Then you could count the textfiles in the directory to know how many are running.
 
Trouble with having textfiles or anything like this, is if the app crashes, you end up with stray/redundant files.
 
Turbopower has a component called onGuard that does this and much more. You can see the number of users, You can create trial and demo programs limited by time, number of uses, number of network users, etc. I think it's about $200. I don't know how they do the code for this though.
 
Hi Ulfeng

I have downloaded the demo from TurboPower but it only detects instances on the same machine and not across the network. Thanks anyway:)

Paul
 
Hi Weez

The app uses Advantage database server but not always (some times just peer to peer file sharing) so I can's always ask the server software.

Thanks
Paul
 
Do you have a master app that is somewhere on a server? If so, you could create a kind of licence deamon, requesting the master app for a validation when the program starts. This can be achived quite easily by placing a server socket in the app, and respond only to validation questions. On startup, you will have to check whether the machine is the master, and, if so, start the listener.

If there is no master app, you could, at startup, broadcast a message across the network, trying to find another instance. If not found, the current instance becomes the number one. Otherwise, the number of already active apps can be returned. Stop the broadcast as soon as you have found another instance.

These are just two possibilities. I hope this helps you in the right direction.
Cheers,
Nico
 
This is the solution

There is no master app but the Broadcast method is just what I want.

How is done???

Regards

Paul
 
Use the Chat example as a starting point.

Instead of the FileConnectItemClick procedure (where the name of the server is asked) use a procedure that finds all computers in the network neighbourhood (for an example of this, see and send a message to each computer found. It is advisable to use a short time-out for this. If no (correct) reply, this is the first instance.

Further, change the ServerSocketClientConnect procedure to:
1. Store the IP address of the client (use a TStringList)
2. Return the list of IP addresses (use SendText)
3. Send the updated list to all other instances

Lastly, remember to notify the others that an instance is shutting down (in the OnClose of the main form), send a message to this effect to all IP addresses in the list.
Cheers,
Nico
 
Nico

You are a star (well ou will be if I can get this going)

Best regards

Paul
 
If you need help, just shout! (And a helpful/expert star would be appreciated too! [dazed])
Cheers,
Nico
 
OK. Give me some time, and I will try to create a shell for you. Should be able to create something this week.
Cheers,
Nico
 
Couple of questions:

1. Kind of network? Is TCP/IP sufficient?
2. O/S'es used?
3. All computers in the same workgroup?
4. Is this some kind of licence protection? (i.e. number of concurrent connections)

Basically, give me some more details, and I will try to cater for all the needs.
Cheers,
Nico
 
Hi couple o answers

1) TCP/IP is all we need to cater for.

2) The application runs on Win98, Me,2000WS and NT

3) Yes, all in same workgrop

4) Yes, this is we have a table that holds the max no of allowed concurent users.

Many thanks

Paul

 
Hi Paul

Unfortunately my time this week is limited, I actually have work to do [smile]

I did a quick search this morning on the web, and found the following: TApp Instance v.1.0 at I haven't downloaded it, thus haven't tested it, but give it a go.

By the way, the description of the component is:

TAppInstance controls all instances of a program in a network. It can be used, to limit the count of users which can run the program at the same time.

It states that it is for D2 and D3, but without too much trouble you should be able to get it running.

Another train of thought: you state that you store the number of allowed instances in the database. Therefore, I guess that one of the first actions of the program is to open the db. Why not create a table that stores the IP's of the connecting instances? I know that this could mean that when a program dies it does not release the instance, but a small utility on the db machine could scan the table periodically, and verify that those instances are still running.

Cheers,
Nico
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top