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

Number of people using program?

Status
Not open for further replies.

ug505

Programmer
Jan 2, 2010
52
US
Hello again all,

Has anyone else seen on Skype where it tells you how many people are online? (How many people are using the program right now.) Is there a way to do that in Delphi? I have a viewing program that gives views to web pages and I'd like to know how many people are using my program. Is there a way to get these numbers and put them in a label?
 
Register with some central service when connecting, and refresh the info every so-many minutes/seconds, so you know the user is still active.
 
Use a socket set, such as the one I just posted in the FAQ: to build a communication between the user's program (using TJDClientSocket) and the central server (TJDServerSocket). I made this so you can A) Login to the server, and B) Send direct packets of info. In this case, on the client's side, you may do something like...

Code:
//Notifying server that program started
Socket.SendPacket(CMD_NOTIFY_ON, []);

//Notifying server that program stopped
Socket.SendPacket(CMD_NOTIFY_OFF, []);

//Ask server for total count of uses
Socket.SendPacket(CMD_GET_COUNT, []);

and then on the server side, you would recognize this command in an event handler...

Code:
procedure TForm1.MySocketCommand(Sender: TObject; Socket: TJDServerClientSocket;
  const Cmd: Integer; const Data: TStrings);
begin
  case Cmd of
    CMD_NOTIFY_ON: begin
      //Client is telling server that it's using program.. do something accordingly
      SomeProcedureWhenStarted(Socket, Data);
    end;
    CMD_NOTIFY_OFF: begin
      //Client is telling server that it stopped using program.. do something accordingly
      SomeProcedureWhenStopped(Socket, Data);
    end;
    CMD_GET_COUNT: begin
      //Client is asking server for count of users - send count
      Socket.SendPacket(CMD_SEND_COUNT, [IntToStr(GetCurrentUserCount)]); //There would be some check for user count here
    end;
    else begin
      //Unrecognized command - raise exception
    end;
  end;
end;

I would be more than happy to build a demo for you with this exact scenario, just let me know. I need to make a demo for the components I built in the FAQ anyway.


JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top