在ipv6 only network上使用Indy IdTelnet

时间:2017-08-29 17:59:16

标签: delphi firemonkey indy

Apple App Store要求应用程序仅适用于仅支持ipv6的网络。 如何让IdTelnet在这样的网络上运行?

1 个答案:

答案 0 :(得分:4)

TIdTelnet具有IPVersion属性,但它被声明为protected,因此无法通过用户代码直接访问。为了设置IPVersion,您可以声明一个hack类,例如:

uses
  .., IdStack, IdGlobal, ..

type
   TIdTelnetHack = class(TIdTelnet)
   published
     property IPVersion;    //expose protected property
   end;

procedure TForm1.TelnetConnect(const aHost:String);
var
  aIPVersion: TIdIPVersion;
begin
  if not IdTelnet1.Connected then 
  begin  //not connected. go connect
    // check if ipv6 or ipv4 network, and support both, 
    try
      GStack.ResolveHost(aHost, Id_IPv6);
      aIPVersion := Id_IPV6;
    except
      GStack.ResolveHost(aHost, Id_IPv4);
      aIPVersion := Id_IPV4;
    end;

    IdTelnet1.Host := aHost;   
    IdTelnet1.Port := 8090;   
    TIdTelnetHack(IdTelnet1).IPVersion := aIPVersion;  //set to IPv4 or IPv6

    IdTelnet1.Connect;
  end;
end;

要在IPv6网络上测试您的应用,请将Mac设置为IPv6接入点,如下所述:

Supporting IPv6 DNS64/NAT64 Networks