I have this piece of code to send a command through UdpClient
and then wait for a response:
cameraListener = new UdpClient(52381);
cameraSender = new UdpClient();
cameraSender.Connect(endPoint);
int dataSent = await cameraSender.SendAsync(command, command.Length);
UdpReceiveResult result = await cameraListener.ReceiveAsync();
Note: "endPoint" is just a normal IPAddress:port endpoint.
What would happen if the Camera
is offline?
Since it is UDP, the SendAsync
will send the data correctly but the ReceiveAsync
will wait for a response forever. And if those two lines of code (the SendAsync
and the ReceiveAsync
) executes periodically, will infinite ReceiveAsync
wait for a response forever until the system would crash?
Or will they terminate or be terminated by OS at some time? Is it essential to implement a Timer to manually "kill" the UDP socket to terminate the eternal waits?