Kbase P108478: 4GL: How to programmatically determine if a client session is running on the same machine as the App
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  9/2/2005 |
|
Status: Unverified
GOAL:
How to programmatically determine if a 4GL client session is running on the same machine as the AppServer?
FIX:
Use the 4GL OS-COMMAND statement to execute the HOSTNAME Operating System Command on both client and AppServer sessions and compare the returned values. For example:
1. The client session procedure, ClientSessionProcedure.p, connects to the AppServer and runs the remote AppServerSessionProcedure.p. Receives the AppServer Session Host Name and compares it to its own Client Session Host Name.
/* 1. ClientSessionProcedure.p */
DEFINE VARIABLE hAppServer AS HANDLE NO-UNDO.
DEFINE VARIABLE lReturnValue AS LOGICAL NO-UNDO.
DEFINE VARIABLE cAppServerSessionHostName AS CHARACTER NO-UNDO.
FUNCTION getClientSessionHostName RETURNS CHARACTER FORWARD.
CREATE SERVER hAppServer.
lReturnValue = hAppServer:CONNECT("-H yshanshixp -AppService myApplicationService").
IF lReturnValue THEN DO:
RUN AppServerSessionProcedure.p ON hAppServer( OUTPUT cAppServerSessionHostName).
IF cAppServerSessionHostName = getClientSessionHostName()THEN
MESSAGE "same machine"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
MESSAGE "different machines"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
ELSE DO:
MESSAGE "AppServer Connection failed"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
QUIT.
END.
FUNCTION getClientSessionHostName RETURNS CHARACTER:
DEFINE VARIABLE c AS CHARACTER NO-UNDO.
OS-COMMAND SILENT hostname > tempfile.txt.
INPUT FROM tempfile.txt.
IMPORT c.
INPUT CLOSE.
OS-DELETEtempfile.txt.
RETURN c.
END FUNCTION.
2. The remote procedure uses the 4GL OS-COMMAND statement to execute its Operating System HOSTNAME command and returns its own Host Name to the calling client procedure:
/* AppServerSessionProcedure.p */
DEFINE OUTPUT PARAMETER cAppServerSessionHostName AS CHARACTER NO-UNDO.
FUNCTION getClientHostName RETURNS CHARACTER FORWARD.
cAppServerSessionHostName = getClientHostName().
FUNCTION getClientHostName RETURNS CHARACTER:
DEFINE VARIABLE c AS CHARACTER NO-UNDO.
OS-COMMAND SILENT hostname > tempfile.txt.
INPUT FROM tempfile.txt.
IMPORT c.
INPUT CLOSE.
OS-DELETE tempfile.txt.
RETURN c.
END FUNCTION.