Try OpenEdge Now
skip to main content
Developing AppServer Applications
Programming ABL Client Applications : Connecting an application service or AppServer instance : Connection examples : Connecting to a session-managed AppServer
 
Connecting to a session-managed AppServer
In this session-managed connection example, the -AppService, -H, and -S parameters are passed as the connection-parameters argument to the CONNECT( ) method. Specific userid and password values are also passed as connection arguments. A value is not supplied for the appserver-info argument. For example:
DEFINE VARIABLE hAppSrv AS HANDLE  NO-UNDO.
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.

CREATE SERVER hAppSrv.
lReturn = hAppSrv:CONNECT
  ("-AppService inventory -H zeus -S 5162","SMITH","STARSHIP").
IF NOT lReturn THEN DO:
  DELETE OBJECT hAppSrv NO-ERROR.
  RETURN ERROR "Failed to connect to Inventory AppServer: " + RETURN-VALUE.
END.
. . .
lReturn = hAppSrv:DISCONNECT().
DELETE OBJECT hAppSrv NO-ERROR.
This code tries to connect an AppServer that supports the application service, inventory. It sends its connection request to a NameServer that runs on a machine with the host name, zeus and is listening on UDP port 5162.
When the CONNECT( ) method executes, the NameServer provides the location of an AppServer broker to the client that supports the inventory application service. The NameServer chooses the AppServer broker randomly from among all AppServers that support the application service and according to load balance settings (if any) established for the application service. The client then connects to the broker, passing the last two method arguments as the first two parameters of the AppServer Connect procedure. The client passes a value of "SMITH" for userid and "STARSHIP" for password. It passes the unknown value (?) for appserver-info because a value is not supplied for it.
If the Connect procedure fails, it could specify a user-defined string. Appending the RETURN-VALUE function to a generic error message in your client-side connection code would capture any user-defined string returned by the AppServer Connect procedure.
Note: The previous code example, and all remaining code examples in this chapter, are presented in simplified form for discussion purposes. In actual practice, you might use the Parameter File (-pf) parameter as the connection-parameters argument and variables to store the userid and password (probably encrypted).