PDA

View Full Version : Determining if a client is connected


Tim Crowell
07-16-2002, 12:47
I am trying to find a way to determine if a particular client is connected or not using the Java API's. Using the getClientInfoById doesn't seem to report information on the clients session. Anyone have any experience with doing this?

reamon
07-16-2002, 14:00
getClientInfoById returns a BrokerClientId object. The public var named "sessions" is an array of BrokerClientSession objects. The BrokerClientSession objects contain all the session info that you can see with Manager. If the array is empty, the client isn't connected.

reamon
07-16-2002, 14:01
Of course by "BrokerClientId" object I meant "BrokerClientInfo" object. Darn fingers just don't work sometimes...

greg
07-16-2002, 15:17
Roughly coded example follows:


import COM.activesw.api.client.BrokerAdminClient;
import COM.activesw.api.client.BrokerClientInfo;

public class ClientConnectionTest extends Object {

public static void main(String[] arguments) {
try {
BrokerAdminClient bac = new BrokerAdminClient(
"localhost","Broker #1","admin1","admin","admin1",null);
String[] clients = bac.getClientIds();
for (int index = 0; index < clients.length; index++) {
BrokerClientInfo info = bac.getClientInfoById(clients[index]);
System.out.println("client " + clients[index] + " has " +
info.sessions.length + " active sessions");
if (info.sessions.length == 0) {
System.out.println(clients[index] + " is not connected");
}
if (info.sessions.length != 0) {
System.out.println(clients[index] + " is connected");
}
}
} catch (Exception e) { e.printStackTrace(); }
}

}

Marta Roca
02-26-2003, 13:33
Hi
I Try the incorporate the code, but show me the below error:
(059) Could not process request document of type "TEST::TryCatchEvent::In_TryCatch_Test"
(109) Run-time exception while processing "Bservicios_Client_Connected"
java.security.AccessControlException: access denied (java.net.SocketPermission

what is happened?

thanks