I create a thread that starts the UDP client that receives the message, after it receives the message that I want to close with the UDP client, and then end the stream, but I donβt know how to end the stream since "Receive", always works until it gets an answer.
This is my code:
private void RecieveChallenge() { UdpClient client = new UdpClient(26000); IPEndPoint remoteIp = new IPEndPoint(IPAddress.Any, 0); Byte[] receivedBytes = client.Receive(ref remoteIp); string ipAddress = Encoding.ASCII.GetString(receivedBytes); }
The important line is client.Receive (ref remoteIp);
This is how I start my stream:
Thread recieveChallengeThread = new Thread(new ThreadStart(RecieveChallenge)); recieveDataThread.Start();
source share