哪位大哥能用Idtcpserver and idtcpclient 写个端口转发=端口映射=数据转发我在网络上搜了好久了也没找到啊  我不想用indy自带的那个转发控件 我想转发的同时数据加密

解决方案 »

  1.   

    使用TIdTCPPortMapper,然后从中做处理.
      

  2.   

    如果要要自行处理,那就通过OnExecute事件(客户端发送来数据时触发),对AContext(TIdContext,实际应该是:TIdMappedPortContext)当中的数据FNetData做加工;OnOutboundData事件则是从远端传回的数据,处理方法是一样的.
      

  3.   

    OnExecute 我接收到数据了 但是数据好像被拦截 不能转发了。这方面的资料真的太难找了
    可以简单写个例子么?发给我么?
      

  4.   


    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;