如何检查TCP端口是否可用Delphi? [英] How to check if a TCP port is available with Delphi?

查看:680
本文介绍了如何检查TCP端口是否可用Delphi?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了捕捉netstat调用之外,还有一种更优雅的方式来检查Delphi中是否提供TCP端口?

Is there a more elegant way of checking if a TCP port is available with Delphi other than catching a netstat call?

推荐答案

我想你可以使用Indy的组件来做到这一点。例如,一个 TIdHTTPServer 会在打开端口时使用异常。

I guess you can use Indy's components to do that. For instance a TIdHTTPServer will raise an exception if a port is in use when it is being opened.

所以基本上您可以创建这样的组件,将其绑定到 localhost:< yourport> ,如果引发异常(捕获并检查它),则该端口可能正在使用,否则它是免费的。

So basically you could create such component, bind it to localhost:<yourport> and if an exception is raised ( catch it and check it ) then the port is probably in use, else it is free.

我猜其他indy组件可以判断一个端口是否打开,但是我现在看不到它。

I guess other indy components can tell if a port is open or not, but I can't look at it right now.

这只是给你一种方法。

这篇关于如何检查TCP端口是否可用Delphi?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆