I am looking for a simple way to see if a remote UDP port is open on a server
BEWARE that several firewalls/network setups/IDS etc. might influence the result... the following method is NOT 100% reliable but it is the only method possible with UDP IMHO (since UDP is connectionless).
You can use UdpClient, set a receive timeout on the underlying socket, make a connection to that remote server/port, Send some small message (byte[]
!) and call Receive.
IF the port is closed you get an exception saying that the connection was forcibly closed (SocketException
with ErrorCode
10054 = WSAECONNRESET
)... which means the port is NOT open.
Otherwise you either receive an answer OR a timeout exception - both should be interpreted as "the UDP port is open".
You can not. That is by design because UDP is connectionless. You have to solve that on application layer.