while ($true) {
do {
try {
Write-Host “Trying to reach “$address”:”$port
$client = New-Object System.Net.Sockets.TcpClient($address, $port)
$stream = $client.GetStream()
$writer = New-Object System.IO.StreamWriter($stream)
$reader = New-Object System.IO.StreamReader($stream)
break
}
catch {
# Try to connect server serval 10s
Start-Sleep -s 10
}
} while ($true)
每隔10秒执行一次,但是为什么没有执行。
1 Answers
Best Answer
$address = "www.pstips.net" $port = 443 while($true) { try { Write-Host “Trying to reach “$address”:”$port $client = New-Object System.Net.Sockets.TcpClient($address, $port) $stream = $client.GetStream() $writer = New-Object System.IO.StreamWriter($stream) $write. $reader = New-Object System.IO.StreamReader($stream) Start-Sleep -s 10 } catch { Write-Host "failed on tcp connect." } }
老铁,确实有效果!感谢你!请问是否可以留下你的联系方式?