开发者

UDP Last Data received timeout from different sources

开发者 https://www.devze.com 2023-02-13 07:55 出处:网络
i have开发者_如何学Go a C# Winform that is accepting UDP Packets from several devices a single port.

i have开发者_如何学Go a C# Winform that is accepting UDP Packets from several devices a single port.

The devices sent UDP packets to me at a set interval and i want to implement a way to know when a device has stopped sending packets.

I use a single UDPClient and using the Receive function. When data is received, i pass the RemoteIPEndPoint back to my mainform to update values.

What would be the best way to this?

Thanks for the help!


This is a little abstract questions and there could be many solutions to that. One simple and quick solution would be to create a HashTable where, HashKey = IP of Remote device Value = Timestamp when last packet received from that device.

Now whenever you receive a packet you just update the hashtable like

if (hashTable contains "RemoteEndPoint") { hashTable [ remoteEndPoint ] = now() // current Time. } else { // if you want to add/register new device to your list, do it here }

Beside that you can just run a Timer with some interval that traverse the HashTable and check if some TimeStamp is less then (currentTime - Your Set Interval), then you can say that you haven't received the data from that end point.

0

精彩评论

暂无评论...
验证码 换一张
取 消