I'm trying to create UDP port checker based on question How to test a remote UDP Port however when connected for example to www.google.com on port range 1-100 I receive for each exception "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". Bellow is code I use.
try
{
UdpClient udpCLient = new UdpClient(Port);
Socket uSocket = udpCLient.Client;
uSocket.ReceiveTimeout = 5000;
uSocket.Connect(Adress, Port);
udpCLient.Connect(Adress, Port);
IPEndPoint RemoteIpEndPoint = new IPEndPoint(Adress, Port);
Byte[] sendBytes = Encoding.ASCII.GetBytes("?");
udpCLient.Send(sendBytes, sendBytes.Length);
Byte[] receiveBytes = udpCLient.Receive(ref RemoteIpEndPoint);
}
catch (SocketException e){
if (e.ErrorCode == 10054)
{
return false;
}
else
return false;
}
return true;
Aucun commentaire:
Enregistrer un commentaire