Так как Вы используете TcpClient
, который означает, что Вы проверяете открытые порты TCP. Существует много хороших объектов, доступных в Система. Сеть. Пространство имен NetworkInformation .
Использование эти IPGlobalProperties
объект добраться до массива TcpConnectionInformation
объекты, которые можно затем опросить о 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.
(defun include-start (line)
"returns the string position after the '#include ' directive or nil if none"
(let ((search-string "#include "))
(when (search search-string line)
(length search-string))))
(defun get-include (line)
(let ((s (include-start line)))
(when s
(subseq line s))))
Я считаю, что заменить в строке
намного проще.
(replace-in-string "#include <stdio.h>" "#include +" "")
=> "<stdio.h>"
Для вашего кода include-start
возвращает начало совпадения, как следует из названия. Вы ищете include-end
, который, вероятно, равен (+ (include-start ....) (length ....))
(defun get-include (s)
(subseq s (mismatch "#include " s)))