Amount of users on network

Amount of users on network

Postby Marc Vanzegbroeck » Sun Oct 06, 2019 8:10 pm

Hi,

Is there a way to see how many users open a FWH program on a network.
I know I can make a counter in a database that increase everytime that program is executed, en decrease while exiting.
The problem there can be that when the program crash, or when the network-connection is broken, the counter is wrong.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Amount of users on network

Postby FranciscoA » Wed Oct 09, 2019 3:30 pm

Hi, please try this:

The UserLogging function creates the txt file for user control when it enters the program and deletes it when it exits.
To view all connected users, you can use the ShowConectedUsers function.
( Idea tomada de un usuario aqui en el foro: hmpaquito)
viewtopic.php?f=6&t=16001&hilit=usuarios+conectados&sid=445b23062ba78d3030099d8213c107bf#p82909
Code: Select all  Expand view
//----------------------------------------------------------------
//USUARIOS CONECTADOS    --  Francisco J. Alegria P. Sept/2010
//----------------------------------------------------------------
//---------------------------------------------------------------//Ctrl usuarios activos en este programa
Function UserLogging(lNew)
local cDirUserLog := cPathDef+"\USERSLOG"
local cUserLog
local cEquipo:=NetName(.f.)
local nHand, FO_SHARED := 64

If !lIsDir(cDirUserLog)  //creamos el sub-dir
   lMkDir(cDirUserLog)
Endif

//cNombUser es static, y se toma del fich de usuarios
cUserLog := cDirUserLog+"\"+Substr(cNombUser,1,12)+cEquipo+".log"

If lNew  //Entrando
  nHand := FCreate( cUserLog )

  FWrite(nHand, cNombUser + CRLF+;       //usuario del programa
                cEquipo   + CRLF+"
")       //nombre del equipo
  FClose(nHand)

  //Lo abrimos en modo shared. (nHandUserLog es static)
  //Cuando se requiere ver los conectados al programa, se trata de abrir en exclusivo,
  //y si no se puede, es que el usuario esta conectado al programa. (Ver ShowConnectedUsers())
  nHandUserLog := FOpen( cUserLog, FO_SHARED ) // abrimos  el fichero compartido

Else  //Saliendo
   FClose(nHandUserLog)
   Ferase(cUserLog)
Endif

Return nil

/* --------------------------------------------------------------------
//Fileio.ch
OPEN MODES:    
FO_READ      0  Open file for reading
FO_WRITE     1  Open file for writing
FO_READWRITE 2  Open file for reading and writing

SHARING MODES:
FO_COMPAT    0 Compatibility mode
FO_EXCLUSIVE 16 Exclusive use
FO_DENYWRITE 32 Prevent other applications from writing
FO_DENYREAD  48 Prevent other applications from reading
FO_DENYNONE  64 Allow others to read or write
FO_SHARED    64 Same as FO_DENYNONE
 -------------------------------------------------------------------- */

//----------------------//Mostrar usuarios activos en este programa
Function ShowConnectedUsers()
local cDirUserLog := cPathDef+"
\USERSLOG"
local aDir := DIRECTORY(cDirUserLog + "
\*.*", )
local nHand, aActiveUsers:={}, cLogText, cFich
local cUserName,cComputName
local FO_EXCLUSIVE:=16

AEVAL( aDir, {|aFich| cFich:=cDirUserLog+"
\"+aFich[F_NAME],;
       if( nHand := FOpen( cFich, FO_EXCLUSIVE ) < 0,;  //si no se abre exclusivo es que usuario esta conectado.
         ( cLogText := MemoRead(cFich),;
           cUserName   := Trim(MemoLine(cLogText, 254,1)),;
           cComputName := Trim(MemoLine(cLogText, 254,2)),;
           aadd( aActiveUsers, {cUserName,cComputName} ) ),;
           FClose(nHand) ) } )

XBrowse(aActiveUsers,"
Usuarios conectados a "+cExeName)
Return nil

Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2157
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Amount of users on network

Postby Marc Vanzegbroeck » Wed Oct 09, 2019 4:21 pm

Francisco,

Thank you for the reply.
Now I have already something like that, but instead of saving it to a file, I save it in the database.
The problem is that when the program is started, it save it to the database, but when the connecting is lost, without exiting the program first, or if the program crashed, the data is still in the database.
So, the other users think that the user is still in the program.

The only way that I can remove it by starting the program again from the same PC/USER.
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: Amount of users on network

Postby Marcelo Via Giglio » Wed Oct 09, 2019 8:08 pm

Hello Marc,

I don't sure, but I think one way can be to lock a record in a table (dbf) users while the user is logged, when the user logout, unlock the record, I think (no sure) when client lost the conection, the record is unlocked automatlicaly, you can test

saludos

Marcelo
Marcelo Via Giglio
 
Posts: 1058
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests