Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top