C# UDP

I'm trying to write a program for udp server in C# and I keep getting the error that says my index was outside the boundary of the array. I have a feeling that it is the line with "byte[] sendbuf..." but I don't see how that could be the problem. This is the code if it helps

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace UDP
{
class Program
{
static void Main(string[] args)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);

IPAddress broadcast = IPAddress.Parse("192.168.1.255");

byte[] sendbuf = Encoding.ASCII.GetBytes(args[0]);
IPEndPoint ep = new IPEndPoint(broadcast, 2424);

s.SendTo(sendbuf, ep);

Console.WriteLine("Message sent to the broadcast address");
}
}
}
If you don't pass any arguments args.Length is 0.
You should check args.Length first.
Topic archived. No new replies allowed.