TAstaServerSocket.SendCodedMessage


 

Applies to
TAstaServerSocket

 

Declaration
procedure SendCodedMessage(ClientSocket: TCustomWinsocket;
  MsgID: Integer; Msg:
string);

 

Description
SendCodedMessage allows you to send special messages throughout an ASTA application. The SendCodedMessage method allows you to roll your own protocol where certain MsgIDs have specific meaning to your application. The ability to create your own protocol in this fashion is a simple yet powerful technique. See the Simple Business Objects code below.

 

The simple code below sends a message from a client to the server, but the message is sent with two different MsgIDs. The server will handle the message differently depending on which of the MsgIDs, 1700 or 1750, accompanies the message.

procedure TForm1.Button4Click(Sender: TObject);
begin
  AstaClientSocket1.SendCodedMessage(1700, eClientCodedMessage.Text);
end;

 

procedure TForm1.Button3Click(Sender: TObject);
begin
  AstaClientSocket1.SendCodedMessage(1750, eClientCodedMessage.Text);
end;

 

The server responds wtih the following implementation code.

 

procedure TForm1.AstaServerSocket1CodedMessage(Sender: TObject;
  ClientSocket: TCustomWinSocket; MsgID: Integer; Msg:
string);

begin

  case MsgID of

    1700: AstaServerSocket1.SendCodedMessage(ClientSocket, MsgID,
            UpperCase(Msg));

    1750: AstaServerSocket1.SendCodedMessage(ClientSocket, MsgID,
            LowerCase(Msg));

  end;

end;

 

When returned to the client, it is picked up in the AstaClientSocket's OnCodedMessage event.

 

 

Simple Business Objects
The following code shows how you could send CodedMessages to a business object instantiated on the server. In this scenario, 1800 and 1850 are "protocol codes" that you control. The client can call those codes, with or without a parameter and invoke a custom response from the server.

 

procedure Form1.AstaServerSocket1CodedMessage(Sender: TObject;
  ClientSocket: TCustomWinSocket; MsgID: Integer; Msg:
string);

begin

  case MsgID of

    1800: begin

            if MyBusinessObject.ChargeSalesTax(StrToInt(Msg)) then

              AstaServerSocket1.SendCodedMessage(ClientSocket,
                MsgID, 'TRUE')

            else

              AstaServerSocket1.SendCodedMessage(ClentSocket,
                MsgID, 'FALSE');

          end;

    1850: begin

           AstaServerSocket1.SendCodedMessage(ClientSocket, MsgID,
             MyBusinessObject.NewCreditLimit(Msg));

          end;

  end;

end;

 

 

 



ASTA Overview TAstaServerSocket.SendBroadcastPopUp TAstaServerSocket.SendSelectCodedMessage