I modified the example posted in doc UdpClient Class so it can operate in a loop. It runs a while and then it stops while I need it to run forever.
The code to reproduce:
/**********************************************************************************************************************************
// See https://aka.ms/new-console-template for more information
//public class UdpClient: IDisposable;
global using System.Net;
global using System.Net.Sockets;
global using System.Text;
void test()
{
UdpClient udpClient = new UdpClient(8888);
udpClient.Connect("192.168.203.18", 8888);
IPEndPoint RemoteIPEndPoint = new IPEndPoint(IPAddress.Any, 0);
Byte[] sendBytes = Encoding.ASCII.GetBytes("Is anybody there today?");
udpClient.Send(sendBytes, sendBytes.Length);
Console.WriteLine("-send completed");
Byte[] receiveBytes = udpClient.Receive(ref RemoteIPEndPoint);
udpClient.Close();
}
Console.WriteLine("Hello, World!");
while (true) test();
**********************************************************************************************************************\
The other side reply's with "acknowledge". (Wemos D1 Arduino)
The debugger shows a constant increase in memory until it stops.
Note I am on an up-to-date windows 11 system. Running visual studio. And it is the first time I use : ".NET6"
Am I doing something wrong?
Thanks for the answer.
Jan