Highlighted
Absent Member.
Absent Member.
863 views

[archive] AcuConnect - Limiting Client Connections

[Migrated content. Thread originally posted on 31 August 2005]

Is there a way to limit the number of time a client is able to connect to a particular instance of acurcl? I would like to be able to stop users from starting multpile instances of our app on their client machine.

Thanks,
JD
0 Likes
2 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] AcuConnect - Limiting Client Connections

There was an example in the forum before to do it from within AcuCOBOL. It works, but it is slow especially over dialup or WAN. The more windows a user has open, the longer it takes. I started out with that approach and was not satisfied. It works much faster to write a DLL. From COBOL, I download the DLL file to the client if it is not there and then call the DLL "COUNTSTP" to tell me the number of interactive sessions. I only wanted to limit interactive sessions, so my DLL compares the window name, this test could be eliminated if you want all thin client sessions.

009990 E500-GET-SESSION-COUNT.
010000 MOVE ZERO TO INTERACTIVE-JOB-COUNT.
010010 IF NOT IS-REMOTE
010020 GO TO E500-EXIT.
010030
010040 SET ENVIRONMENT "DLL-CONVENTION" TO "1".
010050 CALL "@[DISPLAY]:C:\USERLO~1\COUNTSTP.DLL"
010060 ON EXCEPTION
010070 MOVE "Y" TO DLL-ERROR
010080 END-CALL.
010090
010100 IF DLL-ERROR = "Y"
010110 MOVE "N" TO DLL-ERROR
010120 MOVE SPACES TO COMMAND-LINE1
010130 STRING "COPY \\", STPSERVER,
010140 "\USERREAD\COUNTSTP.DLL C:\USERLO~1\"
010150 DELIMITED BY " "
010160 INTO COMMAND-LINE1
010170 CALL "C$SYSTEM" USING COMMAND-LINE1, 200
010180
010190 CALL "@[DISPLAY]:C:\USERLO~1\COUNTSTP.DLL"
010200 ON EXCEPTION
010210 MOVE "Y" TO DLL-ERROR
010220 END-CALL.
010230
010240 IF DLL-ERROR = "Y"
010250 DISPLAY "DLL STPCOUNT NOT FOUND"
010260 LINE 25
010270 GO TO E500-EXIT.
010280
010290 CALL "@[DISPLAY]:CountSTPSessions"
010300 GIVING INTERACTIVE-JOB-COUNT
010310 ON EXCEPTION
010320 MOVE "Y" TO DLL-ERROR
010330 END-CALL.
010340
010350 IF DLL-ERROR = "Y"
010360 DISPLAY "DLL ERROR TO STPCOUNT"
010370 LINE 25
010380 GO TO E500-EXIT.
010390
010400 E500-EXIT.
010410 CANCEL ALL.
010420


Borland C++ DLL
//---------------------------------------------------------------------------

#include
#include
#include
#include
long LookAtAllWindows(long, long);

int NumFound;



#pragma argsused
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return 1;
}

long LookAtAllWindows(long X, long Y)

{char WindowName [255];
char ClassName [255];
char *buf1 = "AcucobolWClass";
char *buf2 = "STP System";
// Go get the windows class name
if (GetClassName(Handle,ClassName,255) > 0)
// Is the window class the same?
if (strcmp(ClassName,buf1) == 0)
// Get its window caption
if (GetWindowText(Handle,WindowName,255) > 0)
// Does this have the same window title?
if (strnicmp(WindowName,buf2, 10)==0)
NumFound++;
return NumFound;
}

///////////////////////////////////////////////////////////////////////


extern "C" __declspec(dllexport) int CountSTP()
{ NumFound = 0;
EnumWindows(LookAtAllWindows),0);
return NumFound;
}
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] AcuConnect - Limiting Client Connections

The Dll I included in the prior post was not the correct one. The correct one is written in Delphi. Here is the source:

library CountSTP;

uses
SysUtils,
Classes,
WinProcs;

var

NumFound : Integer;

{$R *.RES}

function LookAtAllWindows(Handle: HWND; Temp: LongInt): BOOL; stdcall;
var
WindowName : Array[0..255] of Char;
ClassName : Array[0..255] of Char;
begin
// Go get the windows class name
if GetClassName(Handle,ClassName,SizeOf(ClassName)) > 0 then
// Is the window class the same?
if StrComp(ClassName,'AcucobolWClass') = 0 then
// Get its window caption
if GetWindowText(Handle,WindowName,SizeOf(WindowName)) > 0 then
// Does this have the same window title?
if StrLIComp(WindowName,'STP System', 10)=0 then
begin
inc(NumFound);
end;
Result := True;
end;


function CountSTPSessions(): Integer; stdcall;
begin
NumFound := 0;
EnumWindows(@LookAtAllWindows,0);
CountSTPSessions := NumFound;
end;


exports
CountSTPSessions;
begin
end.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.