现在的位置: 首页 > 综合 > 正文

indy 封包转发

2012年10月20日 ⁄ 综合 ⁄ 共 1064字 ⁄ 字号 评论关闭
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;

抱歉!评论已关闭.