第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在C#中,如何檢查TCP端口是否可用?

在C#中,如何檢查TCP端口是否可用?

在C#中,如何檢查TCP端口是否可用?在C#中使用TcpClient或通常連接到套接字我怎樣才能首先檢查我的機(jī)器上某個(gè)端口是否空閑?更多信息: 這是我使用的代碼:TcpClient c;//I want to check here if port is free.c = new TcpClient(ip, port);
查看完整描述

3 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

由于您正在使用a TcpClient,這意味著您正在檢查打開的TCP端口。System.Net.NetworkInformation命名空間中有許多可用的好對(duì)象。

使用該IPGlobalProperties對(duì)象獲取對(duì)象數(shù)組,TcpConnectionInformation然后可以查詢端點(diǎn)IP和端口。


 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;
   }
 }

 // At this point, if isAvailable is true, we can proceed accordingly.


查看完整回答
反對(duì) 回復(fù) 2019-08-24
  • 3 回答
  • 0 關(guān)注
  • 1076 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)