UDP Server Application program
<p>I'm not sure how to fix this, but I'm having a problem with this line in particular
 throw new System.ArgumentException("Syntax: timeclnt ServerName PortNumber 1");  .....any clue what the heck to do? The server application will need to be provided a port number on which to listen, but how?</p>

<pre><code>using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class TimeClient
{
    public static int Main(String[] args)
    {
        if (args.Length &lt; 2 || args.Length &gt; 2)
            throw new System.ArgumentException("Syntax: timeclnt ServerName PortNumber 1");

        String hostName = args[0];
        int portNum = Int32.Parse(args[1]);

        try
        {
            // Define a string to send to the server
            string stringData = "From the timeClient";

            // Encode it properly
            byte[] data = Encoding.ASCII.GetBytes(stringData);

            // Define a UDP client connection
            UdpClient client = new UdpClient();

            // Send some data to the server
            client.Send(data, data.Length, hostName, portNum);

            //where to listen for a UDP response
            IPEndPoint recvpt = new IPEndPoint(IPAddress.Any, 0);

            // get the data back from the server
            byte[] receivedData = client.Receive(ref recvpt);

            // output the data received
            Console.WriteLine("{0}", Encoding.ASCII.GetString(receivedData));

            // all done
            client.Close();
        }

        catch (Exception e)
        {
            // display an error
            Console.WriteLine(e.ToString());
        }

        return 0;
    }
}
</code></pre>
