I am currently writing a program that listens on UDP 67 (DHCP). For some reason, there seems to be a delay of 1-2 minutes to receive datagrams - but only on WinForms. When executing in a console applications, everything works as intended, with no noticeable delay ( < 10 seconds). I'm using the identical code for each.
Edit: Also note, that sometimes the message doesn't come in for over 5 minutes. Restart the program, it might come in.
Second Edit: Wireshark shows traffic coming in - but my application doesn't ever get it.
Any ideas?
Console Code:
private const int listenPort = 67;
private static void StartListener()
{
bool done = false;
UdpClient listener = new UdpClient(listenPort);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
try
{
while (!done)
{
Console.WriteLine("Waiting for broadcast");
byte[] bytes = listener.Receive(ref groupEP);
int len = bytes.Length;
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
listener.Close();
}
}
public static int Main()
{
StartListener();
return 0;
}
WinForms Code:
private const int listenPort = 67;
public DHCPServer()
{
StartListener();
}
private void StartListener()
{
bool done = false;
UdpClient listener = new UdpClient(listenPort);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, listenPort);
try
{
while (!done)
{
byte[] bytes = listener.Receive(ref groupEP);
int len = bytes.Length;
}
}
catch (Exception e)
{
}
finally
{
listener.Close();
}
}