views:

30

answers:

1

When I use netcat to send a udp query I get a full response. When I use UDPCLIENT class in c#, i dont receieve the full response, it is cut short. Here is my code

byte[] data = new byte[1024];
            string stringData;

            UdpClient server = new UdpClient(currentIP, currentport);

            IPEndPoint send = new IPEndPoint(IPAddress.Any, 0);

            string query = "\\players\\";
            data = Encoding.ASCII.GetBytes(query);
            server.Send(data, data.Length);

            data = server.Receive(ref send);


            stringData = Encoding.ASCII.GetString(data, 0, data.Length);

            MessageBox.Show(stringData);

How do I increase the receieve buffer so that it stores the full UDP response?

+1  A: 

First: UDP is not a guaranteed protocol; it's entirely possible that the message is being lost and is permanently inaccessible.

Second, just because you called receive doesn't mean you got everything. You need to keep receiving and parsing the received data until whatever application-level protocol you happen to be using (there doesn't appear to be one in your example) tells you it's time to stop receiving and deal with the message.

Randolpho
Hi thanks for your reply. there is a constistency in how much data gets through these are not lost packets. its the same amount i get everytime. If i use netcat to send the udp query i get all the data back. if i try server.Receive(ref send); a second time no more data comes through, am i missing something?,
brux