now i did a 'hack' that works for me. :)
public class TimedUdpClient : UdpClient
{
private int timeout = 1000; // 1 sec default
private Thread timeoutWatchdog;
/// /// Get/Set the receiving timeout in milliseconds (1000 = 1sec)
///
public int Timeout
{
get { return timeout; }
set { timeout = value; }
}
public new byte\[\] Receive(ref IPEndPoint remote)
{
timeoutWatchdog = new Thread(new ThreadStart(StartWatchdog));
timeoutWatchdog.Start();
try
{
byte\[\] ret = base.Receive(ref remote);
return ret;
}
catch (SocketException)
{
return null;
}
}
private void StartWatchdog()
{
Thread.Sleep(timeout);
this.Send(new byte\[\] {0x00},1,"",8000);
}
}
my little test-program from two or three postings above didn't receive the packets since they have to be sent on the same socket (at least i believe that). when this byte from my watchdog is sent, there's an exception ("connection closed by remote" or something like that) raised somewhere inside UdpClient.Receive(). it would be nicer, if it would just receive the byte and one could distinguish by the sender, if that packet was sent by the watchdog (thus, on the same socket) or comes from outside. UDP is a connectionless protocol, so i'm not sure, how such a connection-closed-excpetion may occur, but actually it does :wtf: anyways. all i wanted, was stop Receive() from blocking and this way it works. :) thx to everyone that helped. (also the ones that read, thought and had no idea) :wq