Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions scripts/Start-EditorServices.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,15 @@ function Test-PortAvailability {
$portAvailable = $true

try {
if ($isPS5orLater) {
$ipAddresses = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList
}
else {
$ipAddresses = [System.Net.Dns]::GetHostEntry("localhost").AddressList
}

foreach ($ipAddress in $ipAddresses)
{
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"

$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
$tcpListener.Start()
$tcpListener.Stop()
}
# After some research, I don't believe we should run into problems using an IPv4 port
# that happens to be in use via an IPv6 address. That is based on this info:
# https://www.ibm.com/support/knowledgecenter/ssw_i5_54/rzai2/rzai2compipv4ipv6.htm#rzai2compipv4ipv6__compports
$ipAddress = [System.Net.IPAddress]::Loopback
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"

$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
$tcpListener.Start()
$tcpListener.Stop()
}
catch [System.Net.Sockets.SocketException] {
$portAvailable = $false
Expand Down