# How to get the number of concurrent users

**URL:** <https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499>\
**Category:** Classic Servoy\
**Created:** [January 28, 2011, 4:37am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499 "2011-01-28T04:37:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![erikd](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erikd](https://forum.servoy.com/u/erikd)\
**Post date:** [January 28, 2011, 4:37am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/1 "2011-01-28T04:37:24Z")

</div>

Hi, anybody knows how to get the number of concurrent users in Servoy? Do I need a plug-in for this?

---

<div class="post-metadata">

**Author:** ![Kahuna](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@Kahuna](https://forum.servoy.com/u/Kahuna)\
**Post date:** [January 28, 2011, 1:19pm UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/2 "2011-01-28T13:19:58Z")

</div>

> erikd:  
> Hi, anybody knows how to get the number of concurrent users in Servoy? Do I need a plug-in for this?

Here is a function I’ve been playing with a short time ago but I’m not sure its working currently as I need to get it up to the server with multiple clients.

For sure it gets the Client count in developer (1 obviously) but does not return any other info so far such as HostID etc. HTH

```auto
function whosLoggedIn()
{
	//Returns an array of JSClientInformation elements describing the clients connected to the server.
	//plugins.maintenance.setMaintenanceMode(true)
	var clients = plugins.maintenance.getConnectedClients();
	//plugins.maintenance.setMaintenanceMode(false)
	//var clients = application.getActiveClientCount(true);
	numberOfClients = clients.length
	////application.output("There are " + clients.length + " connected clients.");
	for (var i = 0; i < clients.length; i++)	
		{
			forms.security_frm_whos_logged_in.vClientID = clients[i].getClientID();
			application.output(' Client ID ' +clients[i].getClientID())
			forms.security_frm_whos_logged_in.vClientUserName = clients[i].getUserName();
			application.output(' User Name ' +clients[i].getUserName())
			forms.security_frm_whos_logged_in.vNumberOfClients = clients.length;
			application.output(' No Client ' +clients.length)
			forms.security_frm_whos_logged_in.vHostConnect = clients[i].getHostIdentifier();
			application.output(' Host ID ' +clients[i].getHostIdentifier())
		}

}

```

---

<div class="post-metadata">

**Author:** ![erikd](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erikd](https://forum.servoy.com/u/erikd)\
**Post date:** [January 31, 2011, 2:05am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/3 "2011-01-31T02:05:25Z")

</div>

Thanks, Kahuna for sharing this.

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [January 31, 2011, 10:47am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/4 "2011-01-31T10:47:20Z")

</div>

you basically need only 2 functions to do this:

application.addClientInfo() to set an identifier for each user you want. (we use this to set the tennant\_id)  
application getClientCountForInfo() to get a count of clients with specific info (in our case the tennant\_id).

---

<div class="post-metadata">

**Author:** ![Kahuna](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@Kahuna](https://forum.servoy.com/u/Kahuna)\
**Post date:** [January 31, 2011, 11:24am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/5 "2011-01-31T11:24:40Z")

</div>

> mboegem:  
> you basically need only 2 functions to do this:
> 
> application.addClientInfo() to set an identifier for each user you want. (we use this to set the tennant\_id)  
> application getClientCountForInfo() to get a count of clients with specific info (in our case the tennant\_id).

Thanks for that Mark - when do you run addClientInfo() ?

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [January 31, 2011, 1:55pm UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/6 "2011-01-31T13:55:39Z")

</div>

> Kahuna:  
> when do you run addClientInfo() ?

It depends on what your goal is, but we need to keep out users when the number of tenant users exceeds the number of users we keep in the tenant record.  
So directly at startup we add the clientinfo (=tenant UUID), then do a count directly after that (this order is needed because a relogin won’t unregister the user from the server)

The number of users we keep in the tenant record are the number of concurrent users the tenant has subscribed to.

---

<div class="post-metadata">

**Author:** ![erikd](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erikd](https://forum.servoy.com/u/erikd)\
**Post date:** [February 1, 2011, 4:37am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/7 "2011-02-01T04:37:35Z")

</div>

Hi Kahuna, I tried your code in the application server above but there was an error in plugins.maintenance.getConnectedClients() syntax. Method returns blank and throws org.mozilla.javascript.EcmaError due to Cannot read property “length” on the variable.

But when I test it in my Servoy Developer it works fine. Do I need to configure application server other than the maintenance.jar file plug-in?

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [February 1, 2011, 7:13am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/8 "2011-02-01T07:13:40Z")

</div>

you can’t use the maintance plugin in a real smart client!  
You can only use it in a pre or post import solution hook…

---

<div class="post-metadata">

**Author:** ![Kahuna](https://avatars.discourse-cdn.com/v4/letter/k/8491ac/32.png) [@Kahuna](https://forum.servoy.com/u/Kahuna)\
**Post date:** [February 1, 2011, 9:45am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/9 "2011-02-01T09:45:21Z")

</div>

> Harjo:  
> you can’t use the maintance plugin in a real smart client!  
> You can only use it in a pre or post import solution hook…

Thanks Harjo

erikd - Use Marks code - it works fine and allows some other neat features too.

Thanks Mark.

---

<div class="post-metadata">

**Author:** ![erikd](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erikd](https://forum.servoy.com/u/erikd)\
**Post date:** [February 1, 2011, 10:48pm UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/10 "2011-02-01T22:48:36Z")

</div>

I already moved to the codes application.getClientCountForInfo() and application.addClientInfo(). I just noticed that when I call application.getClientCountForInfo() it only decreases its value by 1 if I close a client application. How do I do this at runtime where I can force application.getClientCountForInfo() to decrease by 1? There is no application.removeClientCountForInfo().

---

<div class="post-metadata">

**Author:** ![erikd](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@erikd](https://forum.servoy.com/u/erikd)\
**Post date:** [February 2, 2011, 3:03am UTC](https://forum.servoy.com/t/how-to-get-the-number-of-concurrent-users/13499/11 "2011-02-02T03:03:34Z")

</div>

> erikd:  
> I already moved to the codes application.getClientCountForInfo() and application.addClientInfo(). I just noticed that when I call application.getClientCountForInfo() it only decreases its value by 1 if I close a client application. How do I do this at runtime where I can force application.getClientCountForInfo() to decrease by 1? There is no application.removeClientCountForInfo().

Another question is, how do I get details/information from the logged users through these functions?
