Search code examples
delphiindy

Indy TIdHTTPServer.OnCommandGet - which port was connected to?


I have a TIdHTTPServer that is reachable on multiple ports (due to migration) and I need to find out where the current data (in OnCommandGet) is coming from. Where can I retrieve the correct port number from?


Solution

  • It is in AContext.Binding.Port.

    Tested with the following in the CommandGet handler for a IdHTTPServer in Delphi 10.3.3:

    AResponseInfo.ContentText := '<!DOCTYPE html><html lang="en"> +
      '<head><title>A Test Response</title></head>' +
      '<body>Target port: ' + IntToStr(AContext.Binding.Port) +
      '</body></html>';