James Teare
James Teare

Reputation: 372

How to test a remote UDP Port

I am looking for a simple way to see if a remote UDP port is open on a server

Upvotes: 2

Views: 14722

Answers (2)

Yahia
Yahia

Reputation: 70379

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".

Upvotes: 9

Luka Rahne
Luka Rahne

Reputation: 10507

You can not. That is by design because UDP is connectionless. You have to solve that on application layer.

Upvotes: 1

Related Questions