I am checking the availability and responsiveness of a remote udp port:
$Udpclient=new-Object system.Net.Sockets.Udpclient $Udpclient.client.ReceiveTimeout=20000 $Udpclient.Connect('',) $AsciiEncoder = new-object system.text.asciiencoding $byte = $AsciiEncoder.GetBytes("Anybody there?") $Udpclient.Send($byte,$byte.length) $IPEndPoint = New-Object system.net.ipendpoint([system.net.ipaddress]::Any,0) $ReceiveBytes = $Udpclient.Receive([ref]$IPEndPoint) $AsciiEncoder.GetString($ReceiveBytes) $Udpclient.close()
When i debug it i can see that all is correct until this line is executed:
$ReceiveBytes = $Udpclient.Receive([ref]$IPEndPoint)
It times out after 20 sec with the following exception:
Exception calling “Receive” with “1” argument(s): “A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”
When i test the availability of the same port with Microsoft’s port query utility i get success in 5 sec:
portqry.exe -n servername -e portnumber -p UDP
i also tried the Test-Port PS script and it failed.
i am puzzled.
Can you help?