Using UdpClient, how do you retry UdpClient.Connect() until it succeeds?
<p>My client/server programs work well with each other, but only when the server is up and running before my client starts. If the client fails to connect on the first try, I can't get it to try again.</p>

<p>Here's my Client's <code>connect</code> method.</p>

<pre><code>public void connect()
    {          
        IPAddress server_address = IPAddress.Parse("127.0.0.1");
        IPEndPoint server_ip = new IPEndPoint(server_address, 5685);
        Console.WriteLine("2");
        bool connected = false;
        while (!connected)
        {
            try
            {
                Console.WriteLine("IN CONNECTED");
                udp_client.Connect(server_ip);
                byte[] send_data = Encoding.ASCII.GetBytes("INIT");
                udp_client.Send(send_data, send_data.Length);
                byte[] received_bytes = udp_client.Receive(ref server_ip);
                string received_data = Encoding.ASCII.GetString(received_bytes);
                if (received_data == "INIT")
                {
                    connected = true;
                    Console.WriteLine("RECEIVED INIT");
                    listen(server_ip);
                }

            }

            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
</code></pre>

<p>What I was hoping to see is the <code>udp_client.Connect(server_ip)</code> to loop until I received that "INIT" message from the server. </p>

<p>As it currently stands, there is no loop. It seems to get stuck on <code>udp_client.Receive(ref server_ip)</code>. </p>

<p>Any help would be appreciated!</p>