tags:

views:

281

answers:

2

Well this is my first udp test program and i think i now understand a bit of it :) any way here is my code so far:

static void Main(string[] args)
        {
            Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            udpSocket.Bind(new IPEndPoint(IPAddress.Any, 111));
            Console.WriteLine("Waiting for connection");
            byte[] buffer = new byte[1024*64];
            int count = udpSocket.Receive(buffer);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 111);
            EndPoint endPoint = (EndPoint)ipEndPoint;
            udpSocket.ReceiveFrom(buffer, ref endPoint);

            Console.WriteLine("Message recived from, " + endPoint.ToString() + " data length: " + count);
            Console.ReadKey();

        }

but how do i make sure that i got the whole packet?

A: 

Your best bet is to check the length field in the UDP header to see if you got enough bytes.

Zed
well i have no idea how i would do that?
Petoj
+3  A: 

You have room for packets up to 64k bytes , which is the max size of a UDP packet. You'll always read the entire packet.

nos