indy 封包转发

type
  TMySuperMappedPortContext
= Class(TIdMappedPortContext)
    public
     
procedure DoEncode;
     
procedure DoDecode;
  End;


implementation

{自定义加密函数}
function EncodeData(Src: String): String;
begin
  Result :
= Src;
end;

{自定义解密函数}
function DecodeData(Src: String): String;
begin
  Result :
= Src;
end;


{自定义加密接口}
procedure TMySuperMappedPortContext.DoEncode;
begin
  FNetData :
= EncodeData(FNetData);
end;

{自定义解密接口}
procedure TMySuperMappedPortContext.DoDecode;
begin
  FNetData :
= DecodeData(FNetData);
end;

{OnBeforeListenerRun事件}
{替换相应的映射消息处理类型}
procedure TForm1.IdMappedPortTCP1BeforeListenerRun(AThread: TIdThread);
begin
  IdMappedPortTCP1.ContextClass :
= TMySuperMappedPortContext;
end;

{OnExecute事件}
{接收到须转发的数据,调用DoEncode进行"加密"}
procedure TForm1.IdMappedPortTCP1Execute(AContext: TIdContext);
begin
 
if AContext is TMySuperMappedPortContext then begin
    TMySuperMappedPortContext(AContext).DoEncode;
 
end;
end;

{OnOutboundData事件}
{接收到须转发的数据,调用DoDecode进行"解密"}
procedure TForm1.IdMappedPortTCP1OutboundData(AContext: TIdContext);
begin
 
if AContext is TMySuperMappedPortContext then begin
    TMySuperMappedPortContext(AContext).DoDecode;
 
end;
end;

posted on 2009-03-02 14:28  jxgxy  阅读(917)  评论(0编辑  收藏  举报

导航