G
Guest
I have the following program
using System;
using System.Collections;
using System.Net.Sockets;
using System.Net;
using System.IO;
public class Test {
public static void Main(string[] s) {
byte[] data;
data = new byte[512];
try
{
UdpClient dnsClient = new UdpClient("192.168.1.9", 100);
//send the data packet
dnsClient.Send(data,data.Length);
IPEndPoint endpoint = null;
//receive the data packet from DNS server
data = dnsClient.Receive(ref endpoint);
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
Console.ReadLine ();
}
}
This program is compiled with a c# console app and startup class changed to
Test
My question is about the UdpClient; since the methods do not return status
values (success or fail) we need to use try/catch, is this correct?
Now,
I am trying to connect to a host "192.168.1.9", which doesn't exist, so I
expect to receive a time-out exception, however, this is not the case.
The call simply waits about 20 seconds, then goes on to the sending
method, which return immediately without any exception printed on the
console. The, when the receiving function is called, the program simply
block foreever, obviously, since there is no such host anyway.
Basically, why doesn't UdpClient throw exceptions?
Thanks.
using System;
using System.Collections;
using System.Net.Sockets;
using System.Net;
using System.IO;
public class Test {
public static void Main(string[] s) {
byte[] data;
data = new byte[512];
try
{
UdpClient dnsClient = new UdpClient("192.168.1.9", 100);
//send the data packet
dnsClient.Send(data,data.Length);
IPEndPoint endpoint = null;
//receive the data packet from DNS server
data = dnsClient.Receive(ref endpoint);
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
Console.ReadLine ();
}
}
This program is compiled with a c# console app and startup class changed to
Test
My question is about the UdpClient; since the methods do not return status
values (success or fail) we need to use try/catch, is this correct?
Now,
I am trying to connect to a host "192.168.1.9", which doesn't exist, so I
expect to receive a time-out exception, however, this is not the case.
The call simply waits about 20 seconds, then goes on to the sending
method, which return immediately without any exception printed on the
console. The, when the receiving function is called, the program simply
block foreever, obviously, since there is no such host anyway.
Basically, why doesn't UdpClient throw exceptions?
Thanks.