Class TAppSrvClient (unit ApsCli)

Inherits from

TComponent

Constructors


constructor Create(AOwner : TComponent);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Functions

procedure Close;

:Close the communication with the application server.

destructor Destroy;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure Send;

:Send a function code and request (parmeters) to the application server.

procedure CrackHeader(AnsBuffer : PChar; AnsLength : Integer; var AnswerStatus : String; var ParamPtr : PChar; var ParamLen : LongInt);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Extract the answer status and separate parameters from header

procedure DataAvailable(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure DnsLookupDone(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure Notification(AComponent: TComponent; operation: TOperation);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure ProcessLine(CmdBuf : PChar; CmdLen : Integer);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure SendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure SessionClosed(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure SessionConnected(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure TriggerAfterSendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure TriggerBeforeSendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure TriggerError(Error : Word; Msg : String);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure TriggerRequestDone(Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

procedure WndProc(var MsgRec: TMessage);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Properties

property Answer : TMWBuffer

:The Answer property holds the answer from the application server.

property FunctionCode : String

:The function code is a string which is used by the application server to know which server object to instanciate to execute the request.

property Port : String

:This is the port number used by the server to listen for clients.

property Server : String

:This is the IP address or hostname for the application server.

property AnswerStatus : String

:The AnswerStatus property hold the ResultStatus returned back by the application server.

property Handle : HWND

:The handle for the hidden window used to send and receive internal messages for component work.

property Request : TMWBuffer

:The request property holds the parameters sent to the application server.

property RequestBody : PChar


property RequestBodyLen : Integer


property RequestHeader : PChar


property RequestHeaderLen : Integer


property WSocket : TWSocket

:WSocket is the reference to the underlaiying TWSocket component used for communication with the application server.

Events

event OnAfterProcessReply : TProcessReplyEvent

:Use to cleanup allocated resources in the OnBeforeProcessReply event handler.

event OnAfterSendRequest : TNotifyEvent

:Use to cleanup allocated resources in the OnBeforeSendRequest event handler.

event OnBeforeProcessReply : TProcessReplyEvent

:The event OnBeforeProcessReply is triggered when a reply have been received from the server, just before it is processed for header and body extraction.

event OnBeforeSendRequest : TNotifyEvent

:The OnBeforeSendRequest event is triggered just before a request and his parameters are sent to the server.

event OnRequestDone : TRequestDone

:When the application server sent the answer to the client, the OnRequestdone event is triggered.

event OnSessionClosed : TSessionClosed

:The event OnSessionConnected is triggered when the connection has been closed.

event OnSessionConnected : TSessionConnected

:The event OnSessionConnected is triggered when the connection has been established with the application server.

Variables

FAnswer : TMWBuffer;


FAnswerStatus : String;


FBannerRcvd : Boolean;


FFunctionCode : String;


FHandle : HWND;


FOnAfterProcessReply : TProcessReplyEvent;


FOnAfterSendRequest : TNotifyEvent;


FOnBeforeProcessReply : TProcessReplyEvent;


FOnBeforeSendRequest : TNotifyEvent;


FOnError : TErrorEvent;


FOnRequestDone : TRequestDone;


FOnSessionClosed : TSessionClosed;


FOnSessionConnected : TSessionConnected;


FPort : String;


FRcvBuf : PChar;


FRcvCnt : LongInt;


FRcvSize : LongInt;


FRequest : TMWBuffer;


FRequestBody : PChar;


FRequestBodyLen : Integer;


FRequestHeader : PChar;


FRequestHeaderLen : Integer;


FServer : String;


FState : TClientState;


FWSocket : TWSocket;



Constructors


constructor Create(AOwner : TComponent);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Functions


procedure Close;

:Close the communication with the application server.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


destructor Destroy;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure Send;

:Send a function code and request (parmeters) to the application server. This is the main function of the component. The communication with the application server is established if needed.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure CrackHeader(AnsBuffer : PChar; AnsLength : Integer; var AnswerStatus : String; var ParamPtr : PChar; var ParamLen : LongInt);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} { Extract the answer status and separate parameters from header


procedure DataAvailable(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure DnsLookupDone(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure Notification(AComponent: TComponent; operation: TOperation);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure ProcessLine(CmdBuf : PChar; CmdLen : Integer);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure SendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure SessionClosed(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure SessionConnected(Sender : TObject; Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerAfterSendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerBeforeSendRequest;

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerError(Error : Word; Msg : String);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure TriggerRequestDone(Error : Word);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


procedure WndProc(var MsgRec: TMessage);

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Properties


property Answer : TMWBuffer

:The Answer property holds the answer from the application server. It is organized as the request: records made of fields. See TMWBuffer description for more details.


property FunctionCode : String

:The function code is a string which is used by the application server to know which server object to instanciate to execute the request. It can be anything but default in the server to the server object name without the leading TServerObject. For example if you made a server object whose class name is TServerObjectGETCLIENT then the function code will be GETCLIENT. This behaviour can be overriden in the server object by overrinding the BuildFunctionCode procedure. The function code is case incensitive.


property Port : String

:This is the port number used by the server to listen for clients. It defaults to 2106 but can be anything. It can even be a symbolic name provided that name is in the 'services' table.


property Server : String

:This is the IP address or hostname for the application server. It is generaly much faster to use the IP address than the hostname because it avoid name resolution each time the communication is established. Name resolution takes time, specially if there are some problem with the DNS. It's better to get the IP address from the server host name at application startup and used the IP address after.


property AnswerStatus : String

:The AnswerStatus property hold the ResultStatus returned back by the application server. It plays the same role as the function code in the request. The meaning for the value is left to the application author. The server and client code does'nt use it. It is just passed from the server to the client. By default the server use numeric values like those used by the HTTP protocol.


property Handle : HWND

:The handle for the hidden window used to send and receive internal messages for component work.


property Request : TMWBuffer

:The request property holds the parameters sent to the application server. The application server uses the function code to know which server object must be instanciated, and pass the paramters to this server object. Parameters can be anything and are consitued of records made of fields. See TMWBuffer object description for details.


property RequestBody : PChar


property RequestBodyLen : Integer


property RequestHeader : PChar


property RequestHeaderLen : Integer


property WSocket : TWSocket

:WSocket is the reference to the underlaiying TWSocket component used for communication with the application server.


Events


event OnAfterProcessReply : TProcessReplyEvent

:Use to cleanup allocated resources in the OnBeforeProcessReply event handler.


event OnAfterSendRequest : TNotifyEvent

:Use to cleanup allocated resources in the OnBeforeSendRequest event handler.


event OnBeforeProcessReply : TProcessReplyEvent

:The event OnBeforeProcessReply is triggered when a reply have been received from the server, just before it is processed for header and body extraction. This event is the right place to decrypt or decompress data sent by the server. The event handler can allocate some resource or memory and change the parameters passed. To free resource and memory, use the OnAfterProcessReply event which will pass the same arguments.


event OnBeforeSendRequest : TNotifyEvent

:The OnBeforeSendRequest event is triggered just before a request and his parameters are sent to the server. The event handler can process the header (RequestHeader, RequestHeaderLen) and the parameters (RequestBody, RequestBodyLen) to encrypt or compress them. If needed, the event handler can reallocate the data elsewhere. If needed, the OnAfterSendRequest event handler can be used to free allocated resources.


event OnRequestDone : TRequestDone

:When the application server sent the answer to the client, the OnRequestdone event is triggered. The corresponding event handler is the right place to test for success or failure, and to parse the answer to extract the returned info to update the user interface or do whatever needs to be done with the request's result.


event OnSessionClosed : TSessionClosed

:The event OnSessionConnected is triggered when the connection has been closed. The event handler is the right place to update some status bar to let the user know he is disconnected from the server.


event OnSessionConnected : TSessionConnected

:The event OnSessionConnected is triggered when the connection has been established with the application server. The event handler is the right place to update some status bar to let the user know he is connected with the server.


Variables


FAnswer : TMWBuffer;


FAnswerStatus : String;


FBannerRcvd : Boolean;


FFunctionCode : String;


FHandle : HWND;


FOnAfterProcessReply : TProcessReplyEvent;


FOnAfterSendRequest : TNotifyEvent;


FOnBeforeProcessReply : TProcessReplyEvent;


FOnBeforeSendRequest : TNotifyEvent;


FOnError : TErrorEvent;


FOnRequestDone : TRequestDone;


FOnSessionClosed : TSessionClosed;


FOnSessionConnected : TSessionConnected;


FPort : String;


FRcvBuf : PChar;


FRcvCnt : LongInt;


FRcvSize : LongInt;


FRequest : TMWBuffer;


FRequestBody : PChar;


FRequestBodyLen : Integer;


FRequestHeader : PChar;


FRequestHeaderLen : Integer;


FServer : String;


FState : TClientState;


FWSocket : TWSocket;