Hi,
I'm writing a UDP Listener to monitor all incoming UDP messages:
private void ReceiveThreadFkt()
{
EndPoint recEP =new IPEndPoint(IPAddress.Any,6000);
while(false == receiveThreadAbort)
{
// Allow thread to sleep completely
if(receiveThreadSleep == false)
{
// Read data if available, else sleep 10 ms
if((0 != udpSocket.Available))
{
byte[] buffer = new byte[udpSocket.Available];
udpSocket.ReceiveFrom(buffer,ref recEP);
ReceiveQueueElement newElement = new
ReceiveQueueElement(buffer,(IPEndPoint)recEP);
lock(receiveQueue.SyncRoot)
{
receiveQueue.Enqueue(newElement);
}
}
else
{ //no bytes available -> sleep 10 ms
Thread.Sleep(10);
}
}
else
{ // if suspended, sleep for 0.3 seconds
Thread.Sleep(300);
}
}
}
As you can see, this thread can be set to a kind of sleep mode, but when it
is waken up again, all the udp messages stored within the socket are read out.
Is there a possibility to clear the socket's internal buffer, so that the
data which arrived while in sleep mode can be flushed??
Thanks,
Robin