Skip to content

Commit c91c8d4

Browse files
committed
Add @rkeithhill's IPv6 socket fix to PSES startup script
1 parent 87087b6 commit c91c8d4

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

module/PowerShellEditorServices/Start-EditorServices.ps1

+9-15
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,15 @@ function Test-PortAvailability {
176176
$portAvailable = $true
177177

178178
try {
179-
if ($isPS5orLater) {
180-
$ipAddresses = [System.Net.Dns]::GetHostEntryAsync("localhost").Result.AddressList
181-
}
182-
else {
183-
$ipAddresses = [System.Net.Dns]::GetHostEntry("localhost").AddressList
184-
}
185-
186-
foreach ($ipAddress in $ipAddresses)
187-
{
188-
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"
189-
190-
$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
191-
$tcpListener.Start()
192-
$tcpListener.Stop()
193-
}
179+
# After some research, I don't believe we should run into problems using an IPv4 port
180+
# that happens to be in use via an IPv6 address. That is based on this info:
181+
# https://www.ibm.com/support/knowledgecenter/ssw_i5_54/rzai2/rzai2compipv4ipv6.htm#rzai2compipv4ipv6__compports
182+
$ipAddress = [System.Net.IPAddress]::Loopback
183+
Log "Testing availability of port ${PortNumber} at address ${ipAddress} / $($ipAddress.AddressFamily)"
184+
185+
$tcpListener = New-Object System.Net.Sockets.TcpListener @($ipAddress, $PortNumber)
186+
$tcpListener.Start()
187+
$tcpListener.Stop()
194188
}
195189
catch [System.Net.Sockets.SocketException] {
196190
$portAvailable = $false

0 commit comments

Comments
 (0)