Home > Software engineering >  How to stop a UdpClient?
How to stop a UdpClient?

Time:10-06

I'm listening to a UDP socket by using an UdpClient:

UdpClient udpClient = new(new IPEndPoint(myLocalAddress, 12345));
udpClient.Receive();

Indeed, this blocks. Because of this, I moved this code in a separate Task.

On a change of the network, I will stop no longer needed UdpClients. For this, I use the NetworkChange.NetworkAddressChanged event.

How can I stop the listening of the UdpClients? The UdpClient.Receive method does not allow a CancellationToken.

  • Related