我正在尝试在 inno setup 中创建以下功能。
用户被要求输入他们希望我的应用程序进行通信的端口。
一旦他们进入端口,他们就可以点击检查按钮。
此检查按钮将运行一些代码来查看安装计算机上的端口是否可用。
到目前为止,我可以为用户创建输入框来输入他们想要测试的端口。我有以下代码来测试端口是否可用。
int port = 456; //<--- This is your value
bool isAvailable = true;
// Evaluate current system tcp connections. This is the same information provided
// by the netstat command line application, just in .Net strongly-typed object
// form. We will look through the list, and if our port we would like to use
// in our TcpClient is occupied, we will set isAvailable to false.
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] tcpConnInfoArray = ipGlobalProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation tcpi in tcpConnInfoArray)
{
if (tcpi.LocalEndPoint.Port == port)
{
isAvailable = false;
break;
}
}
Console.WriteLine("Port is available");
我的第一个问题是:是否可以从端口测试代码返回 inno setup 的 true 或 false 值?如果它是假的,那么我需要让用户知道。
我的第二个问题是:端口测试代码是否正确?
我的第三个问题是:我的想法是否正确,我可能需要在防火墙中打开该端口。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)