Delphi 正在检测 Indy 客户端组件的本地端口

Delphi detecting local port of the Indy Client Component

我需要知道 Indy TCP 客户端组件在与服务器连接时的本地端口。 在我阅读手册时,BoundPort 是 Indy Client 组件的本地端口。 但是这个值总是returns0,不是真正的本地端口。 真的 BountPort 表示客户端组件的本地端口吗?我在得到它时犯了错误? 或者,还有其他检测本地端口的好方法吗?

TIdTCPClient.BoundPort 属性 是您希望客户端绑定到本地的端口。默认情况下为 0,因此客户端可以绑定到任何可用的随机端口。不管BoundPort设置成什么,TIdTCPClient.Connect()方法成功后,TIdTCPClient.Socket.Binding.Port属性中实际绑定的端口是可用的。