How to test a remote UDP Port

前端 未结 2 390
一生所求
一生所求 2020-12-03 20:03

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

相关标签:
2条回答
  • 2020-12-03 20:50

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

    0 讨论(0)
  • 2020-12-03 20:57

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

    0 讨论(0)
提交回复
热议问题