Hello,
I am a beginner at C# and am using it to develop an application to control a robot remotely. To communicate with the robot I am using UDP. I am able to successfully send instructions to it but when I try to receive a response in the form of a string I only receive the first character out of the whole string. The code I am using to communicate using UDP is as follows:
I am a beginner at C# and am using it to develop an application to control a robot remotely. To communicate with the robot I am using UDP. I am able to successfully send instructions to it but when I try to receive a response in the form of a string I only receive the first character out of the whole string. The code I am using to communicate using UDP is as follows:
Code:
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.2.102"), 54125);
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
string start = "start";
byte[] data = new byte[1024];
data = Encoding.ASCII.GetBytes(start);
server.SendTo(data, data.Length, SocketFlags.None, ipep);
IPEndPoint client = new IPEndPoint(IPAddress.Parse("192.168.2.102"), 54125);
EndPoint Remote = (EndPoint)client;
data = new byte[1024];
int recv = server.ReceiveFrom(data, ref Remote);
label.Text = Encoding.ASCII.GetString(data, 0, recv);
server.Close();
Comment